Find system language to localize

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: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
trevix
Posts: 373
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Find system language to localize

Post by trevix » Thu Mar 15, 2018 8:09 pm

I have been using this script on opening, in order to find out what is the preferred user language, on desktop:

Code: Select all

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-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
      replace quote with "" in 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 if
end getUserLang
I feel that there should be a IDE function to easily return this, like, I thing, mobilePreferredLanguages() does for mobile.
Is there? Is any system var that can be used? If not it would be a great addition...
Regards
Trevix

Klaus
Posts: 10105
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Find system language to localize

Post by Klaus » Thu Mar 15, 2018 10:48 pm

Unfortunatley no IDE function for this.

But this sounds like a good candidate for an enhancement request:
http://quality.livecode.com :D

trevix
Posts: 373
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Find system language to localize

Post by trevix » Fri Mar 16, 2018 10:48 am

Done (21075).
I spend more time in the LC quality center, then in developing my stuff...sigh
Trevix

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 2507
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria
Contact:

Re: Find system language to localize

Post by richmond62 » Fri Mar 16, 2018 7:12 pm

I'm going to be "nasty" about languages . . .

Consider:

1. I run several Polycarbonate iMacs running either Mac OS 10.6 or 10.7 that have, as their system language "English" (presumably US English, although I've never bothered to find out), but with a selection of Keyboard layouts (including, among others, Bulgarian).
sysPrefsX.png
There are 2 "things" (I've outlined them in red) where one can fiddle around with languages:

The "Language & Text" one allows one to set up a sort of hierarchy of languages
one might prefer (never used by me).

The "keyboard" one allows one to activate multiple keyboard layouts.

How in "the hairy Mary" is LiveCode going to get info about a hierarchy of preferred languages?

2. I run a large number of generic PCs running various distros and recensions of those distros of Linux:
again, one can "fa*t around" with language settings left, right and centre.

trevix
Posts: 373
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: Find system language to localize

Post by trevix » Fri Mar 16, 2018 7:43 pm

Apparently, according to Panos, is not that difficult:
http://quality.livecode.com/show_bug.cgi?id=21075

I don't understand just why LC has not this built in (beside, in LC 8.1.9 doesn't work)

As for the OSX keyboard language, I am not sure of how this matter.
Trevix

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”