Multilingual dialogues
Marielle Lange
mlange at lexicall.org
Tue Oct 25 05:51:00 EDT 2005
On Oct 20, 2005, at 12:33 PM, David Bovill wrote:
> Thanks - sounds good. And perhaps if all the language stacks were
> substacks of stack "Translations" or.... then it would be easy to
> add another translation and a script could automatically figure out
> how many were available?
Here is the trick I use:
On any object that requires localisation, create a custom property
called something like
loc("Title","items")
--- Note, a third parameter may need to be added to handle
switching between multiple localisation (depends if you want to give
the user the opportunity to switch between languages or rather
provide him with one localisation only)
Title is the tag, items is the column to fetch in the localisation
file (here the column with the list of items to fill for a pulldown
button).
You have a file with localisation information (here in German). I
**strongly** recommend the localisation to be kept outside of
revolution (though this may cause problems when unicode is required).
------------------------------------------------------------
Title Title Mein Title Herr;Frau;Dr.;Mag
FirstName Vorname Meine Vorname
SecondName Nachname
ArtistName Kuenstler Name
------------------------------------------------------------
The structure of this file is as follows:
TagName TagLabel TagDescription TagItems
Then you have this handler at card or stack level, as appropriate:
------------------------------------------------------------
#####################################################
##
## Get Localisation Information
##
## This Information is found in the file: localization.xml
## The structure of this file is: Tag (tab) Localiz Label
(tab) Localiz Description (tab) Localiz Items
function getLocalValue pLocal
--- Easy way to recover column number according to column name ----
set the itemdel to ","
put "name,label,desc,items" into tLocalCols --- this
greatly simplifies maintainability of the code.
--- Only one line to modify if you change the
structure of your local file
--- Could be defined as a constant (very top of the
script)
repeat with x = 1 to the number of items in tLocalCols
put x into AColNb[item x of tLocalCols]
end repeat
------------------------------------------------------------------------
--------------------------------------
split pLocal by "," -- Tag, column name
put getFileContent(pathLocaliz) into tLocal -- This function
is not provided here but it is obvious to understand what it does
-- for me, I use constant pathLocaliz = "xml/
localization.xml" (replace by what is
-- appropriate)
put offset(cr & value(pLocal[1] ) & tab, tLocal) into tSTart; add
1 to tStart
if it > 0 then get offset(cr, tLocal, tStart+2)
if tStart > 0 and it > 0 then
put char tStart to (tStart+it) of tLocal into tLine
set the itemdel to tab
return item AColNb[value(pLocal[2] )] of tLine
end if
return Alocal
end getLocalValue
------------------------------------------------------------
Then you need to add some handlers at card level to automatically
fill the content of any control which has a custom property cLoc that
is not empty.
------------------------------------------------------------
on preopencard
repeat with x = 1 to (the number of controls of this card)
if the cLoc of control x of this card is empty then next repeat
put (getLocalValue(char 5 to -2 of tItems)) into tLoc
switch (word 1 of the name of control x of this card)
case "field"
--- Fill the control as appropriate
case "button"
--- Fill the control as appropriate... pseudocode here
if the style of control x is "menu" then
-- replace ";" with cr in tLoc
-- cLoc(tTag, "items") goes into the text
else
-- cLoc(tTag, "label") goes into the label
end if
end repeat
end preopencard
If you only have menu buttons, you can fill them automatically
Note that I am not processing unicode text here... The get local
value and the preopencard handler should be modified to handle this.
------------------------------------------------------------------------
--------
Marielle Lange (PhD), Psycholinguist
Alternative emails: mlange at blueyonder.co.uk, M.Lange at ed.ac.uk
Homepage
http://homepages.lexicall.org/mlange/
Easy access to lexical databases http://lexicall.org
Supporting Education Technologists http://
revolution.lexicall.org
More information about the use-livecode
mailing list