In the example below all the strings used in the ULP are listed in the string array I18N[], preceeded by a string containing the various language codes supported by this ULP. Note the vtab characters used to separate the individual parts of each string (they are important for the lookup function) and the use of the commas to separate the strings. The actual work is done in the function tr(), which returns the translated version of the given string. If the original string can't be found in the I18N array, or there is no translation for the current language, the original string will be used untranslated.
The first language defined in the I18N array must be the one in which the strings used throughout the ULP are written, and should generally be English in order to make the program accessible to the largest number of users.
Example
string I18N[] = { "en\v" "de\v" "it\v" , "I18N Demo\v" "Beispiel für Internationalisierung\v" "Esempio per internazionalizzazione\v" , "Hello world!\v" "Hallo Welt!\v" "Ciao mondo!\v" , "+Ok\v" "+Ok\v" "+Approvazione\v" , "-Cancel\v" "-Abbrechen\v" "-Annullamento\v" }; int Language = strstr(I18N[0], language()) / 3; string tr(string s) { string t = lookup(I18N, s, Language, '\v'); return t ? t : s; } dlgDialog(tr("I18N Demo")) { dlgHBoxLayout dlgSpacing(350); dlgLabel(tr("Hello world!")); dlgHBoxLayout { dlgPushButton(tr("+Ok")) dlgAccept(); dlgPushButton(tr("-Cancel")) dlgReject(); } };
Index | Copyright © 2005 CadSoft Computer GmbH |