Below is an extensive routine I wrote based on hints from BuddyAPI's site
and some other people. It tells me the country on the PC, but I'm still
loking for a better Mac solution.
Anyone wanting to provide more info about the stuff I might have missed,
I'm open to suggestions.
It requires BuddyAPI on the PC and baLanguage on the Mac (a separate Beta
Xtra from the BuddyAPI guy)
You can use the Regional Setting control panel to test various stuff. There
is no need to reboot for Windows to give you a different reading for the
country, etc. I tested only English, French and German.
For this product, I'm only interested in British English, German, and
French, so I don't use the locale, but I do detect it and return it in the
list structure.
Enjoy,
Bruce
>Is there any way of getting the locale from director? the Environment will
>tell you the UI language and OS language, but it doesn't tell you whether
>it's Canadian, Belgian, or Standard French.
>
on determineLanguage
gLanguage = getLanguageInfo()[#language]
return gLanguage
end determineLanguage
-- Determine whether language is German, English, or French
-- put getLanguageInfo()
-- put getLanguageInfo()[#language] returns one of:
-- #French, #German, #UK, or #US
on getLanguageInfo
unknown = #unknown -- #UK, #US, #English
temp = [:]
temp[#regLangCode] = unknown
temp[#regLangString] = unknown
temp[#regLang] = unknown
temp[#regLocale] = unknown
temp[#INIsLang] = unknown
temp[#INIsCountry] = unknown
temp[#INIiCountry] = unknown
temp[#osLang] = unknown
temp[#uiLang] = unknown
temp[#language] = unknown
if the platform contains "Windows" then
-- Windows
-- #language: #French, #regLang: "French"
-- #language: #German, #regLang: "German"
-- #language: #UK, #regLang: "English"
-- This requires BuddyAPI
-- if xtraInstalled ("BudAPI") then
-- The langCode is "0000040C" for "French (Standard)" and "00000809"
for "English (British)"
langCode = baReadRegString("Control Panel\International", "Locale",
"error", "HKEY_CURRENT_USER")
if langCode <> "error" then
temp[#regLangCode] = langCode
-- The language string and language codes are as follows fro English,
German, and French
-- "French (Belgian)" "0000080C"
-- "French (Canadian)" "00000C0C"
-- "French (Luxembourg)" "0000140C"
--"French (Swiss)" "0000100C"
-- "French (Standard)" "0000040C"
-- "German (Austrian)" "00000C07"
-- "German (Liechtenstein)" "00001407"
--"German (Luxembourg)", "00001007"
-- "German (Standard)" "00000407",
-- "German (Swiss)" "00000807"
-- "English (Australian)" "00000C09"
-- "English (Canadian)" "00001009"
-- "English (Caribbean)" "00002409"
-- "English (Ireland)" "00001809"
-- "English (Jamaica)" "00002009"
-- "English (New Zealand)" "00001409"
-- "English (South Africa)" "00001C09"
-- "English (British)" "00000809"
-- "English (United States)" - "00000409"
langString = baReadRegString
("System\CurrentControlSet\Control\Nls\Locale", langCode, "error",
"HKEY_LOCAL_MACHINE")
if langString <> "error" then
temp[#regLangString] = langString
-- Attempt to parse it into separate language and locale
localeStart = offset(" (", langString)
if localeStart = 0 then
temp[#regLang] = temp[#regLangString]
temp[#regLocale] = EMPTY
else
l = length(langString)
temp[#regLang] = langString.char[1..localeStart-1]
-- Delete the space, the "(" and the ending ")"
locale = langString.char[localeStart+2..l-1]
temp[#regLocale] = locale
end if
end if -- if valid langString
end if -- If valid langCode
-- Here is a list of the possible language code returned by
-- "sLanguage" , sCountry, iCountry (see below) and what they mean:
-- "sCountry" indicates the county's name, "iCountry" returns an code,
such as "61" closely approximate to phone dialing prefix
-- csy = Czech
-- dan = Danis
-- dea = German (Austrian) "Austria" "43"
-- dec = German (Liechtenstein) "Liechtenstein" "41"
-- del = German (Luxembourg) "Luxembourg" "352"
-- deu = German (Standard) "Germany" "49"
-- des = German (Swiss) "Switzerland" "41"
-- ell = Greek
-- ena = English (Australia) "Australia" "61"
-- enc = English (Canada) "Canada" "2"
-- enb = English (Caribbean) "Caribbean" "1"
-- eni = English (Ireland) "Ireland"
"353"
-- enj = English (Jamaica) "Jamaica" "1"
-- eng = English (British) "United Kingdom" "44"
-- ens = English (South Africa) "South Africa" "27"
-- enu = English (United States) "United States" "1"
-- enz = English (New Zealand) "New Zealand" "64"
-- esn = Modern Spanish
-- esm = Spanish (Mexican)
-- esp = Castilian Spanish
-- fin = Finnish
-- fra = French (Standard) "France" "33"
-- frb = French (Belgian) "Belgium" "32"
-- frc = French (Canadian) "Canada" "2"
--frl ="French (Luxembourg)" "Luxembourg "352"
-- frs = French (Swiss) "Switzerland" "41"
-- hun = Hungarian
-- isl = Icelandic
-- ita = Italian
-- its = Italian (Swiss)
-- nlb = Dutch (Belgian)
-- nld = Dutch
-- non = Norwegian (Nynorsk)
-- nor = Norwegian (Bokmal)
-- plk = Polish
-- ptb = Portuguese (Brazilian)
-- ptg = Portuguese (Portugal)
-- rus = Russian
-- sky = Slovak
-- svc = Swedish
-- trk = Turkish
temp[#INIsLang] = baReadINI ("intl", "sLanguage", EMPTY, "WIN.INI")
temp[#INIsCountry] = baReadINI ("intl", "sCountry", EMPTY, "WIN.INI")
temp[#INIiCountry] = baReadIni ("intl", "iCountry", EMPTY,
"WIN.INI")
-- Make a final decision
case (temp[#regLang]) of
"French":
temp[#language] = #French
"German":
temp[#language] = #German
otherwise
-- Defaults to British English
temp[#language] = #UK
end case
-- end if -- If BuddyAPI is installed
else
-- Macintosh
-- See also the UI helper Xtra's getLanguage() function
--The IDs of the itl2 resource".
-- *getLanguage -- 0=english,1=japanese,2=french,3=german
-- 0 = English
-- 1 = (French or) Japanese?
-- 2 = (Japanese or) French?
-- 3 = German
-- 4 = Italian?
-- 5 = Dutch?
-- 7 = Swedish?
-- 8 = Spanish?
-- 9 = Danish ?
-- 11= French Canadian?
-- 12 = Norwegian?
-- 17 = Finnish?
-- 71 = Brasil?
-- 19456 = Russian ?
-- This requires the Buddy Xtra called baLanguage, shipped separately
-- * baLanguage -- returns number of default Language
-- 0 = English
-- 1 = French
-- 2 = German
-- What about Japanese?
case (baLanguage()) of
0: -- #English
temp[#language] = #UK
1:
temp[#language] = #French
2:
temp[#language] = #German
otherwise:
-- Defaults to British English
temp[#language] = #UK
end case
end if -- If Macintosh
env = the environment
-- Newly supported in D8. Could be useful, but we're not using D8.
-- Returns "English", "Spanish", or sometimes #other?
if voidP(env[#osLanguage]) then
temp[#osLang] = unknown
else
temp[#osLang] = env[#osLanguage]
end if
-- Pretty useless. Returns authoring tool language, not target machine
language
if voidP(env[#uiLanguage]) then
temp[#uiLang] = unknown
else
temp[#uiLang] = env[#uiLanguage]
end if
return temp
end getLanguageInfo
Bruce Epstein, Zeus Productions, [EMAIL PROTECTED], 732-940-2800
Check out LAST CALL - The Ultimate Bartending Sim:
http://www.zeusprod.com/games/lastcall.html
Director and Lingo in a Nutshell (DiaN/LiaN) kick butt.
Free Sample Chapters: http://www.zeusprod.com/nutshell/downloads/
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]