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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
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 ...shaosean wrote:Nothing built in, so you either need to shell it or write an external.
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
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
Hi Jens,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