Determine active OS langguage

Trevor DeVore lists at mangomultimedia.com
Wed Oct 5 13:07:36 EDT 2005


On Oct 5, 2005, at 2:37 AM, graham samuel wrote:

> Hi Trevor
>
> Tried your function out on a French Windows XP SP2 system running  
> RunRev 2.6 (after taking out spurious returns) and it didn't work -  
> it just returned "en" because your registry query put nothing into  
> tUserLangs. I am no expert, but it looks to me as if the Registry  
> entries in the French system are under Control Panel\International 
> \iCountry or \sCountry or \sLanguage
>
> The value of iCountry on my system is 33 [which is the  
> international phone code] and of sCountry is France [which is of  
> course both French and English for France - presumably a German  
> system for example would not say 'Germany' but 'Deutschland', but I  
> haven't got a system to test it on) and of sLanguage is FRA. There  
> is also \Locale which is a Hex figure 0000040C.
>
> I'll experiment further it you would like to suggest which  
> direction to take.

Thanks for a taking a look at this Graham.  Let me walk through the  
logic of the function to see where it might be going wrong.

Right now the function queries the "HKEY_CURRENT_USER\Control Panel 
\International\Locale" which returns the hex value you noted above.   
This hex value is a combination of a primary and sublanguage  
identifier which you can find information about here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/ 
nls_238z.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/ 
nls_61df.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/ 
nls_19ir.asp

What my code is supposed to do is extract the primary language  
identifier from the registry value which I can compare against the  
documented values that Microsoft provides.

So for French (Standard) we start with the hex value 0x040c (what  
your system has).  In order to extract the primary language  
identifier from the language identifer (0x040c) we need to do a  
bitAND operation.  Somewhere deep in the microsoft site it tells you  
that that value to use for this operation is 0x3FF (or 1023) in  
decimal form but I can't find the reference right now.  Revolution  
requires the decimal form when using bitAND so we end up with this:

get queryRegistry("HKEY_CURRENT_USER\Control Panel\International 
\Locale") --> RETURNS HEX
get baseConvert(it,16,10) --> CONVERT HEX TO DECIMAL (1036 FOR FRENCH  
STANDARD)
get it bitAND 1023

Using the value you gave for your system (0x040c) the value of it in  
the above transcript ends up being 12 which is what I would expect it  
to be for French.  I wonder if maybe there was a problem when you  
copied and pasted the script.  I uploaded a stack to my user space on  
RevOnline.  Look for getUserLang under "trevordevore".  There is just  
one button to click and it will display the language your os is  
running (for english, french, german, spanish and italian).  Could  
you let me know if that works on your system?  The version of the  
function is slightly updated in the stack so if it does work there  
could have been a problem in my original function.

Thanks,


-- 
Trevor DeVore
Blue Mango Multimedia
trevor at mangomultimedia.com





More information about the use-livecode mailing list