Checking language settings on Mac/Win desktop

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jens.greiner
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Jun 01, 2011 10:35 am

Checking language settings on Mac/Win desktop

Post by jens.greiner » Fri May 25, 2012 11:50 pm

How could I find out what language/locale settings are used on a desktop Mac and Win?

I'd like to set the user interface to the language the underlying system uses. Couldn't find a corresponding LiveCode command to check it.

May be there is a better way to get the settings then using a shell command.

Thank you! :)
Mac OSX 10.7.4 Lion, LiveCode 5.5 (Commercial)
on MacBook Pro 2.66GHz Intel Core i7 8GB RAM
Targets: iOS (iPhone 3GS, iPhone 4(s), iPad2), Android (Emulator), Mac, Windows, LC-Server (On-Rev)

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Checking language settings on Mac/Win desktop

Post by shaosean » Sat May 26, 2012 8:23 am

Nothing built in, so you either need to shell it or write an external.

gpb01
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Sat Jun 04, 2011 5:41 pm

Re: Checking language settings on Mac/Win desktop

Post by gpb01 » Sat May 26, 2012 11:55 am

shaosean wrote:Nothing built in, so you either need to shell it or write an external.
Mmm ... probably is time to think to an external for this ... I'm not sure that with 'Mountain Lion' and 'Sandboxing' you can still easily continue to call Shell functions ... :(

Guglielmo

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Checking language settings on Mac/Win desktop

Post by shaosean » Sat May 26, 2012 2:16 pm

I think I already have the code for Mac OS X so let me dig it out next week and you can give it a test to see f it works in rate sandbox.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Checking language settings on Mac/Win desktop

Post by Klaus » Tue May 29, 2012 4:47 pm

Hi friends,

I found something from the LiveCode mailing list on my hd, don't know who the author was/is...

Code: Select all

function dptGetLang
    -- Returns the language of the session of the user.
    -- This function will read the operation system configuration and will
  ##  return the current language used by the user.
    local theItemNo,theLangCode,theLangStrings
    local theVersion,theWinLangCodes
    local theUserLang = "en"
   
    if the platform is "MacOS" then
        put replacetext(shell("defaults read NSGlobalDomain AppleLanguages"),"(\s|\(|\)|" & quote & ")","") into theLangStrings
        put char 1 to 2 of theLangStrings into theUserLang
    else if the platform is "Win32" then
        -- http://windowssdk.msdn.microsoft.com/en-us/library/aa365069.aspx
        -- http://windowssdk.msdn.microsoft.com/en-us/library/ms776286.aspx
        --http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/mui_GetUILanguageInfo.asp
        -- http://support.microsoft.com/kb/181604
       
        ## FIRST CHECK FOR MUI INSTALLS
        if queryregistry("HKEY_LOCAL_MACHINE\MUI\Enable") is 1 then
            put queryregistry("HKEY_CURRENT_USER\MUI\CurLang") into theLangCode
        end if
       
        if theLangCode is empty then
            put word 2 of the systemversion into theVersion
           
            if word 1 of the systemversion is "Windows" then    # 95/98/ME
                put queryregistry("HKEY_CURRENT_USER\Control Panel\desktop\ResourceLocale") into theLangCode
            else if theVersion >= 4 and theVersion < 5 then    # NT
                put queryregistry("HKEY_USERS\.DEFAULT\Control Panel\International\Locale") into theLangCode
                ## THIS COULD FAIL IN WHICH CASE YOU HAVE TO CHECK THE RESOURCES OF SOME INSTALLED DLL.
                ## VERY SILLY.edit script the
            else    # XP/Vista
                put queryregistry("HKEY_CURRENT_USER\Control Panel\International\Locale") into theLangCode
            end if
        end if
       
        put word 1 to -1 of theLangCode into theLangCode
    ## Vista bug in version up to 2.9 rc-2: trailing white space
       
        put baseconvert(theLangCode,16,10) into theLangCode
       
        ## THE ORDER OF THIS LIST MATCHES THE ORDER OF theLangCodes
        put "za,al,fr,et,dz,bh,eg,iq,jo,kw,lb,ly,ma,om,qa,sa,sy,tn,ae,ye,am,in,az,az,ru,es,by,ba,ba,fr,bg,es,hk,mo,sg,fr,ba,hr,cz,dk,af,mv,be,nl,au,be,ca,in,ie,ie,jm,my,nz,ph,sg,za,tt,gb,us,zw,ee,fo,ph,fi,be,ca,fr,lu,mc,ch,nl,es,ge,at,de,li,lu,ch,gr,gl,in,ng,il,in,hu,is,ng,id,ca,ca,ie,it,ch,jp,in,kz,kh,gt,rw,in,kr,kg,la,lv,lt,de,lu,mk,bn,my,in,mt,nz,cl,in,ca,mn,cn,np,no,no,fr,in,af,ir,pl,br,pt,pt,in,bo,ec,pe,ro,ch,ru,fi,no,se,fi,no,se,fi,no,se,in,ba,ba,cs,cs,za,za,lk,sk,si,ar,bo,cl,co,cr,do,ec,sv,gt,hn,mx,ni,pa,py,pe,pr,es,uy,ve,ke,fi,se,se,sy,tj,dz,in,ru,in,th,cn,tr,tm,cn,ua,de,pk,uz,uz,vn,gb,sn,za,ru,cn,ng,za" into theLangStrings
        put "1078,1052,1156,1118,5121,15361,3073,2049,11265,13313,12289,4097,6145,8193,16385,1025,10241,7169,14337,9217,1067,1101,2092,1068,1133,1069,1059,8218,5146,1150,1026,1027,3076,5124,4100,1155,4122,1050,1029,1030,1164,1125,2067,1043,3081,10249,4105,16393,6153,6153,8201,17417,5129,13321,18441,7177,11273,2057,1033,12297,1061,1080,1124,1035,2060,3084,1036,5132,6156,4108,1122,1110,1079,3079,1031,5127,4103,2055,1032,1135,1095,1128,1037,1081,1038,1039,1136,1057,2141,1117,2108,1040,2064,1041,1099,1087,1107,1158,1159,1111,1042,1088,1108,1062,1063,2094,1134,1071,2110,1086,1100,1082,1153,1146,1102,1148,1104,2128,1121,1044,2068,1154,1096,1123,1065,1045,1046,2070,2070,1094,1131,2155,3179,1048,1047,1049,9275,4155,5179,3131,1083,2107,8251,6203,7227,1103,26,6170,3098,2074,1132,1074,1115,1051,1060,11274,16394,13322,9226,5130,7178,12298,17418,4106,18442,2058,19466,6154,15370,10250,20490,3082,14346,8202,1089,2077,1053,1053,1114,1064,2143,1097,1092,1098,1054,1105,1055,1090,1152,1058,1070,1056,2115,1091,1066,1106,1160,1076,1157,1144,1130,1077" into theWinLangCodes
    
        set wholematches to true
        put itemoffset(theLangCode, theWinLangCodes) into theItemNo
        if theItemNo > 0 then
            put item theItemNo of theLangStrings into theUserLang
        end if
    else
        ## LINUX
        return char 1 to 2 of $LANG -- Easy Unix.
    end if
   
    return theUserLang
end dptGetLang
But this does also work with shell on the Mac...

Best

Klaus

jens.greiner
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Jun 01, 2011 10:35 am

Re: Checking language settings on Mac/Win desktop

Post by jens.greiner » Tue May 29, 2012 6:36 pm

Hi all,

thank you all for your answers.

I'll check and try the script Klaus provided tomorrow. Since I don't know anything about Externals development I have to wait if somebody else will find a solution if the above mentioned script don't works.
Right now I let the user choose the language at the first start of the app. But I would prefer an automated solution for more comfort. ;-)

I'll let you know, if the script is working for me.

Regards,
Jens
Mac OSX 10.7.4 Lion, LiveCode 5.5 (Commercial)
on MacBook Pro 2.66GHz Intel Core i7 8GB RAM
Targets: iOS (iPhone 3GS, iPhone 4(s), iPad2), Android (Emulator), Mac, Windows, LC-Server (On-Rev)

gpb01
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Sat Jun 04, 2011 5:41 pm

Re: Checking language settings on Mac/Win desktop

Post by gpb01 » Tue May 29, 2012 7:59 pm

Hi Jens,
here a little bit update version of the Klaus code (... if I remember, some languages was missed) :

Code: Select all

function osGetLang
   local theItemNo, theLangCode, theLangStrings
   local theVersion, theWinLangCodes, theUserLang
   --
   put "en" into theUserLang
   if the platform is "MacOS" then
      put replacetext(shell("defaults read NSGlobalDomain AppleLanguages"),"(\s|\(|\)|" & quote & ")","") into theLangStrings
      put char 1 to 2 of theLangStrings into theUserLang
   else if the platform is "Win32" then
      -- http://windowssdk.msdn.microsoft.com/en-us/library/aa365069.aspx
      -- http://windowssdk.msdn.microsoft.com/en-us/library/ms776286.aspx
      -- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/mui_GetUILanguageInfo.asp
      -- http://support.microsoft.com/kb/181604
      ## FIRST CHECK FOR MUI INSTALLS
      if queryregistry("HKEY_LOCAL_MACHINE\MUI\Enable") is 1 then
         put queryregistry("HKEY_CURRENT_USER\MUI\CurLang") into theLangCode
      end if
      if theLangCode is empty then
         put word 2 of the systemversion into theVersion
         if word 1 of the systemversion is "Windows" then    # 95/98/ME
            put queryregistry("HKEY_CURRENT_USER\Control Panel\desktop\ResourceLocale") into theLangCode
         else if theVersion >= 4 and theVersion < 5 then    # NT
            put queryregistry("HKEY_USERS\.DEFAULT\Control Panel\International\Locale") into theLangCode
            ## THIS COULD FAIL IN WHICH CASE YOU HAVE TO CHECK THE RESOURCES OF SOME INSTALLED DLL.
            ## VERY SILLY.edit script the
         else    # XP/Vista
            put queryregistry("HKEY_CURRENT_USER\Control Panel\International\Locale") into theLangCode
         end if
      end if
      put word 1 to -1 of theLangCode into theLangCode
      ## Vista bug in version up to 2.9 rc-2: trailing white space
      put baseconvert(theLangCode,16,10) into theLangCode
      ## THE ORDER OF THIS LIST MATCHES THE ORDER OF theLangCodes
      put "za,al,fr,et,dz,bh,eg,iq,jo,kw,lb,ly,ma,om,qa,sa,sy,tn,ae,ye,am,in,az,az,ru,es,by,ba,ba,fr,bg,es,hk,mo,sg,fr,ba,hr,cz,dk,af,mv,be,nl,au,be,ca,in,ie,ie,jm,my,nz,ph,sg,za,tt,gb,us,zw,ee,fo,ph,fi,be,ca,fr,lu,mc,ch,nl,es,ge,at,de,li,lu,ch,gr,gl,in,ng,il,in,hu,is,ng,id,ca,ca,ie,it,ch,jp,in,kz,kh,gt,rw,in,kr,kg,la,lv,lt,de,lu,mk,bn,my,in,mt,nz,cl,in,ca,mn,cn,np,no,no,fr,in,af,ir,pl,br,pt,pt,in,bo,ec,pe,ro,ch,ru,fi,no,se,fi,no,se,fi,no,se,in,ba,ba,cs,cs,za,za,lk,sk,si,ar,bo,cl,co,cr,do,ec,sv,gt,hn,mx,ni,pa,py,pe,pr,es,uy,ve,ke,fi,se,se,sy,tj,dz,in,ru,in,th,cn,tr,tm,cn,ua,de,pk,uz,uz,vn,gb,sn,za,ru,cn,ng,za" into theLangStrings
      put "1078,1052,1156,1118,5121,15361,3073,2049,11265,13313,12289,4097,6145,8193,16385,1025,10241,7169,14337,9217,1067,1101,2092,1068,1133,1069,1059,8218,5146,1150,1026,1027,3076,5124,4100,1155,4122,1050,1029,1030,1164,1125,2067,1043,3081,10249,4105,16393,6153,6153,8201,17417,5129,13321,18441,7177,11273,2057,1033,12297,1061,1080,1124,1035,2060,3084,1036,5132,6156,4108,1122,1110,1079,3079,1031,5127,4103,2055,1032,1135,1095,1128,1037,1081,1038,1039,1136,1057,2141,1117,2108,1040,2064,1041,1099,1087,1107,1158,1159,1111,1042,1088,1108,1062,1063,2094,1134,1071,2110,1086,1100,1082,1153,1146,1102,1148,1104,2128,1121,1044,2068,1154,1096,1123,1065,1045,1046,2070,2070,1094,1131,2155,3179,1048,1047,1049,9275,4155,5179,3131,1083,2107,8251,6203,7227,1103,26,6170,3098,2074,1132,1074,1115,1051,1060,11274,16394,13322,9226,5130,7178,12298,17418,4106,18442,2058,19466,6154,15370,10250,20490,3082,14346,8202,1089,2077,1053,1053,1114,1064,2143,1097,1092,1098,1054,1105,1055,1090,1152,1058,1070,1056,2115,1091,1066,1106,1160,1076,1157,1144,1130,1077" into theWinLangCodes
      set wholematches to true
      put itemoffset(theLangCode, theWinLangCodes) into theItemNo
      if theItemNo > 0 then
         put item theItemNo of theLangStrings into theUserLang
      end if
      if theUserLang is "ch" then
         switch theLangCode
            case 2064
               put "it" into theUserLang
               break
            case 4108
               put "fr" into theUserLang
               break
            case 2055
            case 1047
               put "de" into theUserLang
               break
            default
               put "en" into theUserLang
               break
         end switch
      end if      
   else
      ## LINUX
      return char 1 to 2 of $LANG -- Easy Unix.
   end if
   --
   return theUserLang
end osGetLang
... but, what would be interesting to know is ... if this code run on OSX in a sandboxed environment because, to get the "Languages" use a shell command and ... I don't know if this is allowd for a sandboxed App. :(

Guglielmo

jens.greiner
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Jun 01, 2011 10:35 am

Re: Checking language settings on Mac/Win desktop

Post by jens.greiner » Tue May 29, 2012 10:59 pm

Hi Guglielmo,

thank you for the update. Sandboxing could be an issue. Nevertheless I will try the code.

At last I have to read the Apple developer docs about this topic.
How ever, if this will be a serious problem I let the user choose the language until there is another solution available.

Cheers,
Jens
Mac OSX 10.7.4 Lion, LiveCode 5.5 (Commercial)
on MacBook Pro 2.66GHz Intel Core i7 8GB RAM
Targets: iOS (iPhone 3GS, iPhone 4(s), iPad2), Android (Emulator), Mac, Windows, LC-Server (On-Rev)

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Checking language settings on Mac/Win desktop

Post by shaosean » Thu May 31, 2012 9:08 am

Finished looking over the locale/language information, and writing it as an external is using pretty much the same calls as the scripts posted above (but in nasty C of course ;-) ) The only other fun stuff it seems to have, we can't use in Rev anyways, so no real point..

gpb01
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Sat Jun 04, 2011 5:41 pm

Re: Checking language settings on Mac/Win desktop

Post by gpb01 » Fri Jun 01, 2012 8:22 am

jens.greiner wrote:Hi Guglielmo,
thank you for the update. Sandboxing could be an issue. Nevertheless I will try the code.

At last I have to read the Apple developer docs about this topic.
How ever, if this will be a serious problem I let the user choose the language until there is another solution available.

Cheers,
Jens
Hi Jens,
I wrote a little external that should probably run also in a sandboxed environment ...

Enclose you will find a little .zip containing both the external bundle and a very simple test program (... which use also a very simple method to dynamically load the external).

Hope this partially help, :)

Guglielmo
Attachments
phxLocale_Test.zip
(5.83 KiB) Downloaded 319 times

jens.greiner
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 14
Joined: Wed Jun 01, 2011 10:35 am

Re: Checking language settings on Mac/Win desktop

Post by jens.greiner » Fri Jun 08, 2012 8:27 pm

Hi all, finally I did some testing and I got the following results.

I tested both the code snippet and the External on a MacOS X Lion system, a MacOS X Mountain Lion, a Windows 7 and a Windows 8 (Preview) system.
The External is of course working in MacOS environments only since you need a .dll version to test it in Windows environments.
The code snippet Klaus and Guglielmo provided is working in every environment. But there are still some restrictions.

MacOS X (all above mentioned versions):
You have to change the Language settings (System Settings->Language & Text->Language) so that English is at the top of the list of languages.
None of the other settings, neither Format nor Region, will change the language displayed to the LiveCode app.
In MacOS English is English. This means that you don't have any difference between English spoken in UK, US, CA or AU. This is different in Windows!

Windows (all above mentioned versions):
You have to change the Format settings (Control Panel->Time, Language & Region->Region & Language->Format tab). None of the other settings will change the language displayed to the LiveCode app.
In Windows the language id shown within LiveCode depends on the Language/Country combinations used in the settings. For example, if you set the format to "French (France)" you will get "fr". If you set the format to "French (Canada)" you will get "ca". But you will get also "ca" if you are using "English (Canada)". On the other hand you will get the string "de" no matter if you set the format to "German (Germany)" or "German (Switzerland)". If you live in Switzerland you get French, Italian, or German depending on the language you are using. In Canada you will get "ca" only regardless of the language you are speaking there.

Considered together I came to the conclusion that I let the user choose between the languages I will provide with the app. It is much easier and more faultless then an automatic language setting. :shock:

Regarding to sandboxing. Does anyone know if sandboxing is just something Apple will test before publishing an app in the AppStore or if it is build in in current developer versions of Mountain Lion? I ask because there war no issue with using the External or code snippet with Mountain Lion.

Thank you very much for the help! :)

Cheers,
Jens
Mac OSX 10.7.4 Lion, LiveCode 5.5 (Commercial)
on MacBook Pro 2.66GHz Intel Core i7 8GB RAM
Targets: iOS (iPhone 3GS, iPhone 4(s), iPad2), Android (Emulator), Mac, Windows, LC-Server (On-Rev)

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Checking language settings on Mac/Win desktop

Post by trevix » Tue Feb 03, 2015 12:16 pm

Just so that everybody knows:
On OSX Mavericks/LV 7.0.2 it bombs.....
Too bad.
Trevix
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

Post Reply