Determining the Active OS Language |
|
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.
/** * 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,pt,zh,zh,zh,zh,ja,ko,ru" --> LANGUAGE CODES THAT WILL BE RETURNED BY FUNCTION local tAppLangsMac = "en,fr,de,es,it,pt,zh-Hans,zh-Hant,zh_TW,zh_CN,ja,ko,ru" --> LANGUAGE CODES THAT MAC OS RETURNS local tAppLangsWin = "9,12,7,10,16,22,4,4,4,4,17,18,25" --> 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 end if if i > 0 then return item i of tAppLangs else return "en" end getUserLang
Posted 10/4/2005 by Trevor Devore to the Use-Revolution List