Silverfrost Forums

Welcome to our forums

Language detection

25 Aug 2010 1:08 #6830

I am trying to identify from within a Fortran95 program the language that the user might prefer to use by default. While trying to find something clues from browsing the web I came across a Windows function called GetSystemDefaultUILanguage that may be what I need, although I'm not entirely sure, and I would not have the faintest idea how to call that routine from within Fortran anyway! Currently I use a fairly crude method: I make a call to getenv@ to query the APPDATA directory, and then detect the language from however 'Application Data' is written. If anyone has some better ideas they would be most appreciated.

27 Aug 2010 8:18 #6850

I'm guessing you need to do something like this. You can search for GetSystemDefaultLangID for more info. You need to link with the Kernel32.DLL using SLINK to access the function. [u:ab083500a0]However[/u:ab083500a0], you can do this [u:ab083500a0]easily[/u:ab083500a0] by just adding kernel32.dll as a reference in PLATO. Right click on your project files and then click add reference. (find it in your windows\system32 directory).

PROGRAM ANON
   C_EXTERNAL GetSystemDefaultLangID 'GetSystemDefaultLangID' : INTEGER*2
   INTEGER*2 :: lang

   ! Get default language according to control panel
   lang = GetSystemDefaultLangID()

   ! Process lang code

END ANON

Codes for different languages are at http://msdn.microsoft.com/en-us/library/dd318693%28v=VS.85%29.aspx and at http://www.science.co.il/Language/Locale-Codes.asp

The codes are in HEX. When I run this in the UK I get code 2057 which is hexadecimal 809 which agrees with the table at the second link above.

I would normally use KIND= to create 2 byte integers but I am unsure what value to use, so I have used INTEGER*2 in the code above.

Have fun David.

Please login to reply.