Page 1 of 1
Localization tutorials ?
Posted: Sat Jan 18, 2014 10:57 am
by jasonshow
I need to localize my apps to support multiple languages,
but I didn't find any tutorials,can anyone tell me ?
(official tutorials are better)
thanks a lot.
Re: Localization tutorials ?
Posted: Sat Jan 18, 2014 11:15 pm
by bn
Hi Jason,
look at the LiveCode User Guide
4.5 UsingPropertyProfiles
currently page 117
to access the User Guide go to "Resources" -> User Guide -> at the bottom right of that page is: "launch PDF"
it describes a way to localize your app to different languages.
Kind regards
Bernd
Re: Localization tutorials ?
Posted: Sun Jan 19, 2014 11:13 am
by jasonshow
thanks,bn !
Property Profiles seems I need to set all languages to every UI component.
if I need to add a new language,someday,i need to find out all of UI components,and one by one add new string to them.
can I just manage all strings in a file,write some codes,and let every UI components auto show the right language ?
thanks a lot !
Re: Localization tutorials ?
Posted: Mon Jan 20, 2014 2:44 pm
by bn
Hi Jasonshow,
can I just manage all strings in a file,write some codes,and let every UI components auto show the right language ?
shure, you can do that easily, you just have to keep the list up to date if you change your stack.
a way to collect all objects of a card and put them into a list in a robust format would be
Code: Select all
on mouseUp
put " of" && the name of this stack into tStackName
put " of" && the name of this card into tCardName
repeat with i = 1 to the number of controls of this card
put the abbrev id of control i & tCardName & tStackName & return after tCollect
end repeat
delete last char of tCollect -- a return
put tCollect into field 1
end mouseUp
you can expand the list to all objects of a stack and all substacks.
You need at least one button that holds above code and one field where the output goes to run this scrpt. Add as many controls to the card as you like.
You could put this list into a tab delimited list and add the language specific words for each language.
It might turn out to be more time consuming than to use the Property Profiles.
Kind regards
Bernd
Re: Localization tutorials ?
Posted: Tue Mar 17, 2015 10:22 am
by trevix
I use Property profile on my desktop app, but i think they are buggy. It's like handling eggs..
Trevix
Re: Localization tutorials ? Properties? umpf...
Posted: Thu Mar 19, 2015 5:20 pm
by trevix
Livecode 7.0.4 rc1, mavericks
Make a new stack
Create 3 buttons
Call btn 1 "Italiano" with the script:
Code: Select all
set the custompropertyset of stack "NameOfTheStack" to "Italiano"
Call btn 2 "English" with the script:
Code: Select all
set the custompropertyset of stack "NameOfTheStack" to "English"
Call btw 3 "BtnExample" with the script:
Code: Select all
set the label of me to the btn_001 of stack "NameOfTheStack"
Create the stack custom property set "Italiano", with the custom properties "btn_001", value "Pulsante Uno"
Create the stack custom property set "English", with the custom properties "btn_001", value "Button One"
What am I missing? If you change the language, push "BtnExample" and its label will become empty.
All of this because, for my project with hundred of fields and btns, I am trying to change the localization method, from Property profiles on each control (works...more or less but revSetStackFileProfile bombs on Linux) to a scripted localization with a unique list of translations.
Should i do it ? Will it takes too much time on preopenstack while changing all these labels, etc ?
Thanks for any help.
Re: Localization tutorials ?
Posted: Sat Mar 21, 2015 8:11 pm
by trevix
Hi Bernd.
I took the liberty to add to your script. I tried it and it works pretty well; even if I am not sure of how fast the second script would be on startup with hundred of buttons and fields...
First you collect your controls data with this:
Code: Select all
on mouseUp
lock screen
set the lockmessages to true
--put the long id of this card into tStartPoint if you have to move form this card
--list all stacks in memory
put revLoadedStacks(Application) into TheStacks
set the itemdel to "|" --to separate the properties
repeat for each line tStack in TheStacks
put " of" && the name of stack tStack into tStackName
repeat for each line tCardID in the cardIDS of stack tStack
put " of" && the name of card ID tCardID into tCardName
repeat with i = 1 to the number of controls of card ID tCardID of stack tStack
put the abbrev id of control i of card ID tCardID of stack tStack & tCardName & tStackName into tControl
put the label of tControl into item 1 of tControlA[tControl] --the label if there is one
put the text of tControl into item 2 of tControlA[tControl] --the text if there is one
put the tooltip of tControl into item 3 of tControlA[tControl] --the tooltip if there is one
replace return with "§" in tControlA[tControl] --this is because the text file must be readable (some items may have return on it)
end repeat
end repeat
end repeat
--make a text file to save to the desktop
combine tControlA using return and "|"
put specialfolderPath("Desktop") & "/ListOfTerms.txt" into tPath
put tControlA into URL ("file:" & tPath)
set the lockmessages to false
unLock screen
end MouseUp
Now we have a nice text file on the desktop that we can translate on whatever language.
Once done it, we load it with all the labels and text of the translation:
Code: Select all
On mouseUp
--now retrieve it
lock screen
set the lockmessages to true
put URL ("file:" & tPath) into tControlA
split tControlA using Return and "|"
---we have the text, now put it back
repeat for each line tControl in the keys of tControlA
replace "§" with return in tControlA[tControl] --some item may have a return (like btn lists)
if item 1 of tControlA[tControl] is not empty then
set the label of tControl to item 1 of tControlA[tControl]
end if
if item 2 of tControlA[tControl] is not empty then
set the text of tControl to item 2 of tControlA[tControl]
end if
if item 3 of tControlA[tControl] is not empty then
set the tooltip of tControl to item 3 of tControlA[tControl]
end if
end repeat
--go tStartPoint -eventually go back to where you were
set the lockmessages to false
unLock screen
I am not sure if this is a correct approach to localization of a Desktop application. And I may miss some control properties.
Any opinions/suggestions?
Trevix
Re: Localization tutorials ?
Posted: Sun Mar 22, 2015 9:18 pm
by bn
Hi Trevix,
I took the liberty to change your scripts.
I am not an expert in localizations. And if you say it somehow bombs for you you could go your scripted way.
But actually setting the property sets should also work if done properly (did not test/don't have Linux) If it does not work it should be reported as bug.
This is a variation of your scripts.
Not that it is inherently different from your approach it is just a different way to do it. It keeps using the array and stores the properties as part of the array.
This way you could even add customProperties to your export.
Have a look. I think it should be pretty fast.
script export
Code: Select all
on mouseUp
lock screen
set the lockmessages to true
--put the long id of this card into tStartPoint if you have to move form this card
--list all stacks in memory
put revLoadedStacks(Application) into TheStacks
repeat for each line tStack in TheStacks
put " of" && the name of stack tStack into tStackName
repeat for each line tCardID in the cardIDS of stack tStack
put " of" && the name of card ID tCardID into tCardName
repeat with i = 1 to the number of controls of card ID tCardID of stack tStack
put the abbrev id of control i of card ID tCardID of stack tStack & tCardName & tStackName into tControl
put the label of tControl into tControlA[tControl]["label"] --the label if there is one
put the text of tControl into tControlA[tControl]["text"] --the text if there is one
put the tooltip of tControl into tControlA[tControl]["toolTip"] --the tooltip if there is one
end repeat
end repeat
end repeat
put arrayEncode(tControlA) into tControlA
put specialfolderPath("Desktop") & "/ListOfTerms.bin" into tPath
put tControlA into URL ("binfile:" & tPath)
set the lockmessages to false
unLock screen
end MouseUp
script import
Code: Select all
On mouseUp
--now retrieve it
lock screen
set the lockmessages to true
put specialfolderPath("Desktop") & "/ListOfTerms.bin" into tPath
put URL ("binfile:" & tPath) into tControlA
put arrayDecode(tControlA) into tControlA
---we have the text, now put it back
repeat for each key tControl in tControlA
-- check if stack is really open do something about non open stacks herre
-- currently it just skips the stack that is not open
put word -2 to - 1 of tControl into tStackName
if not (there is (tStackName)) then next repeat
repeat for each key aProp in tControlA[tControl]
set the aProp of tControl to tControlA[tControl][aProp]
end repeat
end repeat
--go tStartPoint -eventually go back to where you were
set the lockmessages to false
unLock screen
end mouseUp
Re: Localization tutorials ?
Posted: Mon Mar 23, 2015 6:04 pm
by trevix
Nice.
The reason I used a split/merge and txt file was so that the txt file could be easily updated for the different languages.
But your solution is better. I could even do a plugin for input of the various languages...
In general though any scripted solution add time to the loading of the application, if you have many controls. What do you thinK?
Re: Localization tutorials ?
Posted: Mon Mar 23, 2015 7:19 pm
by bn
Hi Trevix,
In general though any scripted solution add time to the loading of the application, if you have many controls. What do you thinK?
sure, but the stacks are in memory and only testing can tell.
Why don't you make a test stack with say 50 controls on a card and then copy that card 50 times.
Actually I just tried this, made a stack of 51 cards with 6 text fields with moderate amount of text in it, 16 label fields, 32 buttons and 6 graphics on each card
That is roughly 3000 objects.
creating the export file including writing took about 180 milliseconds on LC 6.7.4 rc1 and about 260 ms on LC 7.0.4 rc 2
reading the export file and setting all properties took 260 ms LC 6.7.4 rc1, 350 ms LC 7.0.4 rc2
I think that is not bad at all as a one time operation during startup. The user expects a little loading time and this adds veryl little.
One can not set the text of a graphic / had to exclude that.
Also you might watch out for images. etc. Just make sure you only gather info you can also set as a property for an object.
Kind regards
Bernd