localize -- enable the automatic localization of ZETA
Not everyone speaks English thus having multiple language support improves the usability of your program. yab provides a very simple language interface with the localize command. Use it once to turn automatic localization on. Now all strings in GUI widgets will be translated automatically if there is a dictionary entry for them. All you have to do, is to make a dictionary for your program.
Dictionaries for stand-alone programs are normally put into the subdirectory Language/Dictionaries of your program. But if a filename Filename$ is given, the (absolute) path of this filename is used as dictionary directory. Note: As long as the yab program is not compiled with the build factory, you should specify the path.
In the dictionary directory there should be files named like the programs name or like file name in Filename$. The files have a language code as ending. The language code consists of a two letter code for the language and a capitalized two letter code of the country. For a sample program named foobar.yab, some example dictionaries: foobar.deDE (language German (de) and country Germany (DE)), foorbar.enUS (language English (en) and country United States (US)), foobar.nlBE (language Dutch (nl) and country Belgium (BE)).
The dictionary contains the English term in paranthesis ("") some spaces as separator and the translated text in the target language in paranthesis too. Example:
# A comment starts with a #
# English German
"This is a sentence." "Dies ist ein Satz."
This all looks complicated, but the reader is encouraged to have a look at the localization of the yab IDE and other tools to understand localization completly.
Note: Menus and dropboxes return messages that contain a string that might be translated. Use the translate$() function to handle these.
Note: The strings are case sensitive!
Note: Currently localization is only supported on ZETA. However, supporting the localization of your program is a good idea for BeOS users too because localization support might be added soon to BeOS yab.
It is good design to support localization.
// this examples works with the example localization file above
// name it "foobar.deDE" in your home directory
window open 100,100 to 200,200, "Win", "Foobar"
menu "File", "Quit", "Q", "Win"
draw text 10,50, "This is a sentence.", "Win"
msg$ = message$
if(instr(msg$, "Quit") or instr(msg$, translate$("Quit"))) quitting = true
window close "Win"
This shows automatic translation of the menu strings "File" and "Quit" and the draw text string. Change the language settings to German in your ZETA preferences. Note: The menu strings are also translated when you do not provide the translation file because ZETA comes with some translations for typical strings used in applications.
Further, we have to check the translation of the message$ too with translate$ because the menu now reports the message string "Datei:Beenden|" when selected in German.