Determine active OS langguage

Trevor DeVore lists at mangomultimedia.com
Tue Oct 4 19:17:51 EDT 2005


On Oct 4, 2005, at 1:58 PM, Trevor DeVore wrote:

> Thanks Ken and Thierry for the info.  I will take a look at these  
> and let you know how it goes.

Here is what I came up with by combing the hints everyone provided.   
My app has language files identified using 2 character language codes  
(en,fr,de,etc).  This function returns one of those language codes  
based on the platform the app is running on.

I've tested on OS X with English, French, German, Spanish and  
Italian.  I tested Win XP with English and it worked but haven't  
tested the other languages yet since I don't have Windows in anything  
but English.  If anyone wants to let me know how it works on their  
international system that would be great.  Otherwise I will just wait  
to hear back from the localization company.

Thanks for the pointers.

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




/**
* Returns the two letter language code that our program can use to  
load a language file.
*
* @return 2 letter lang
*/
function getUserLang
     local tAppLangs = "en,fr,de,es,it"      --> LANGUAGE CODES THAT  
WILL BE RETURNED BY FUNCTION
     local tAppLangsMac = "en,fr,de,es,it"   --> LANGUAGE CODES THAT  
MAC OS RETURNS
     local tAppLangsWin = "9,12,17,10,6"     --> DECIMAL  
REPRESENTATIONS OF PRIMARY LANGUAGE CODES WINDOWS RETURNS
     local tUserLangs
     local i

     set wholeMatches to true

     if platform() is "MacOS" then
         put replaceText(shell("defaults read NSGlobalDomain  
AppleLanguages"),"(\s|\(|\))","") into tUserLangs

         repeat for each item tLang in tUserLangs
             put itemOffset(tLang, tAppLangsMac) into i
             if i > 0 then exit repeat
         end repeat
     else if platform() is "Win32" then
         put queryRegistry("HKEY_CURRENT_USER\Control Panel 
\International\Locale") into tUserLangs
         put baseConvert(tUserLangs,16,10) bitAND 1023 into tUserLangs

         repeat for each item tLang in tUserLangs
             put itemOffset(tLang, tAppLangsWin) into i
             if i > 0 then exit repeat
         end repeat

     --> LINUX
     else

     end if

     if i > 0 then return item i of tAppLangs
     else return "en"
end getUserLang




More information about the use-livecode mailing list