Android app localization

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Android app localization

Post by MaxV » Wed Oct 29, 2014 2:54 pm

Hello,
I would like to write my app with localization to many languages (English, Italian, French, Chinese, etc.)
So I started working with profiles, switching the stack to the correct profile would change language app.
Unfortunately I realized that this way works only on PCs, mobile devices don't support profile changes. :cry:
What is your strategy for mobile app localization?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

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

Re: Android app localization

Post by trevix » Mon Mar 16, 2015 1:11 pm

Your question went unanswered...too bad.
I have been dealing with localization on desktop apps using Custom Properties, but found that the "revSetStackFileProfile" is often buggy and sometime profile properties disappear...
Beside, as someone noted, I would like to have all the various text translation in only one place, so as to make it easier for to modify them.

I thought about doing the change of labels, etc, one by one on the PreOpenStak script, may be with some kind of repeat, but I was worry that for complex stacks it would slow too much the start up of the app. With hundred of btns and labels I would probably also get some error in card/stack/substack paths...

I believe that since LC people are so busy on building on various LiveCode incarnation (the last one, LC 8 is going to be another major change), they are loosing their grip on bug solving (!), localization (how could this not be considered important..!), desktop development (it's harder and harder to understand if a post, a script, a function are meant for Desktop or Mobile application...)

Over here we say: too many irons in the fire.
Trevix
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android app localization

Post by sphere » Mon Mar 16, 2015 8:09 pm

Well an idea could be you create a button which every time it is pushed, the card changes untill the language comes by they prefer. and then also save the last choice for next startup.
There is a lesson how to save these thing within the app. but you could also write a text file with these settings in it and read it while opening the stack, setting the last choices at startup.

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

Re: Android app localization

Post by trevix » Tue Mar 17, 2015 10:19 am

I use this script, that I found on the web, and it works very well on desktop app (don't know on mobile).

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,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 if
end getUserLang
Detecting the language is not a problem for me. And sure, you can save everything on a file.
But suppose you have a stack with 10 substacks, btns, fields, dialogs, error caching, etc.
Once detected the language (or from a user choice), your script has to pinpoint each and every control in order to change the label of the content of the dialog (the property of control X of card yy of stack ZZ) before showing the app to the user.
If you misplace a path to a control, your app will bomb.And this operation, on the standalone, will have to be done at each launch. Not very speedy. In my case I also have to handle the date and time change across the application...
My point is that "Properties profile" is a good idea. But it must be fixed, work on mobile and somehow to be able to get the content from a file or global var
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android app localization

Post by sphere » Tue Mar 17, 2015 10:28 am

Maybe this link will help you on the way saving the properties.

http://lessons.runrev.com/m/4071/l/1737 ... pplication

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

Re: Android app localization

Post by trevix » Tue Mar 17, 2015 10:50 am

Yes...but this makes things a little more complicate when you deal with launch of your app from the doc it generate (double click on the doc of app XX).
I am not saying that it cannot be done. But localization should be a robust, easy thing to deal with and my feeling is that it is not now.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Android app localization

Post by bwmilby » Fri Sep 29, 2017 1:02 am

I know this is a very old post, but I think I've found a way to get profiles to work on mobile. I've tested the attached stack on iOS and am able to successfully switch between 2 profiles.

First, I had to do a hack and edit revSaveAsStandalone(.livecodescript)... I just did it in the IDE knowing it would revert when I exited
I just added a single line to force inclusion of profile data.

Code: Select all

private command revSetStackProps pStack
   put "*" into sStandaloneSettingsA["includeProfiles"] -- force profiles into built stack
Next, include revCommonLibrary and revProfilesLibrary scripts inside the stack (put the scripts in buttons for the demo).
Last, insert both library scripts into back once the stack loads.

When you launch the demo app, the grow/shrink buttons will just make the stack fill the screen and go back to iPhone 4 size. (You will need to provide a splash screen image though.)
After adding the Common library (with the button), the geometry manager works and the controls will resize.
After adding the Profile library (with the button), the profile manager works and the buttons will change color based on the profile.

I'm not sure if there are any reasons not to do this in production, but thought I'd offer it as a possible solution. I will note that the revCommonLibrary does redefine revMail and it will no longer use the native function and switch you over to the mail client (at least on iOS). I'm not sure if there is anything else in there that will cause issues. In reality, much of the code in that library isn't required, so it could be cut down quite a bit if you just wanted geometry/profile support.
Attachments
GeoTest.livecode.zip
Test Stack
(20.95 KiB) Downloaded 244 times
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

AndyP
Posts: 614
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Android app localization

Post by AndyP » Fri Sep 29, 2017 10:36 am

What I normally do with multi languages is to have the text required for each language in a text file with the following format.

the name of the text file = the language required.

e.g. English.txt Deutsch.txt ...

Each text file follows the following conventions.

Name of control,text,control width
Name of control,text,control width
Name of control,text,control width...

e.g
English.txt
button "Help",Help,55
Field "UserName",Please enter your username,167

Deutsch.txt
button "Help",Hilfe,55
Field "UserName",Bitte geben Sie Ihren Benutzernamen ein,236

Then I have a dropdown menu where I replace the first char of each line (x) with a flag image for each country, this is followed by the country name.
This dropdown is also populated from a text file and the flag images are in a referenced folder.

selecting an entry from the dropdown loads the associated country.txt file and then loops through each line in the item-delimited list ..

get the left pos of the current control (this changes if the width of the control is changed)
replace the controls text
adjust the width
reset the left pos to the value just stored

when all this has been done I write the current language to another txt file so that when the app restarts it knows which language to load.
I also have all the lines of the English.txt file in a hidden field in the app so that if the language file selected is not found at startup the controls will all be set as per the lines of the hidden field.

I've found this method to be very reliable with the addition that it makes adding new languages or updating existing language files very simple.
Andy Piddock
https://livecode1001.blogspot.com Built with LiveCode
https://github.com/AndyPiddock/TinyIDE Mini IDE alternative
https://github.com/AndyPiddock/Seth Editor color theming
http://livecodeshare.runrev.com/stack/897/ LiveCode-Multi-Search

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Android app localization

Post by sphere » Fri Sep 29, 2017 5:14 pm

Great tip AndyP.

I was also thinking about how to cope with it.
First i though'd putting all needed languages in the card script en selct a language in a settings card. And then a lot of if then else.

But yours is a brighter idea.

At websites they often use a standard sentence and then that sentance will be changed to the language selected, (just can't remember now how it's called, a linefill or something)

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

Re: Android app localization

Post by trevix » Sat Sep 30, 2017 11:41 am

Two years later I'm here to report how I decided to solve the localisation problem for my App (FlowReminder...sigh...still not finished, but this is not my main occupation.
The App is quite big, multi-languages, multi calendar, with a splash Standalone, has user created templates and able to download updates.

There are 3 different language updates:
1 - a Dialog.tx file in the form "number tab language1 tab language 2 tab ...". I edit it at will during development.(for example: "15 Not found. Non trovato.")
2 - a Languages.tab text file, in the form: Field X of group W of card Y of stack Z
3 - a scripted language change for a few controls of the Application template document.

1 - In the splash, on the first launch, the user is asked to choose the language.
The Dialog.txt file is loaded at launch, converted to array, only for the correct language, and used every time there is a ask/answer dialog (potentially quite long)

2 - The language.tab file is used for UI elements all over the App
Once in a while, before creating a standalone, I run a script that collect every UI visible text: Buttons and Fields that have a prefix in their name (like "T_") . I import it in Filemaker DB, update languages and then export it to a tab file.
It contains items like "Cancel", "Save", "Up", "Down", "Edit, etc that need to be in the proper language.
The file gets loaded when the language is chosen on first launch and applied to every control that need it, saving then the stack (the real App)

3 -Finally, since the user is able to create template in any language and, because of that, also to switch the template language at will, basic controls and help text of templates are changed when shown. There are not so many so this work pretty fast with a script inside the template stack.

I did all this because I think it is very important to have all the languages centralised on a few files, so to avoid translation mistakes and be able to easily add a language, without hunting for controls.
So, when the user has chosen the language, every other launch is pretty fast because most of the controls have been modified in the stack that is the real App (placed in the computer Application support library). Still the user is able, from the splash, to reload a different language. Also, inside the App, the user can see how a template looks on different languages.

As for the text width, I arranged every control so to fit the different languages, to not make things over complicate.

I hope this will help.
Trevix
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>

Post Reply

Return to “Android Deployment”