Localization / Localized strings |
Understand the rules for using localized strings at runtime.
The compiled string files (.42s) must be distributed with the program files in a directory specified in the DBPATH/FGLRESOURCEPATH environment variable.
The locale (LANG/LC_ALL) corresponding to the encoding used in the .42s files must be set before starting the application. If the locale is wrong, the strings will not be loaded properly.
The .42s compiled string resource files are loaded in following order of precedence:
For each string file, the runtime system looks in the following directories:
Like .42m program pcode files, the .42s string resource files are shared by all fglrun processes running on the computer: The string file is loaded into memory with the mmap operating system function.
Specify a list of compiled string files with entries in the FGLPROFILE configuration file with the fglrun.localization entries.
fglrun.localization.file.count = integer
fglrun.localization.file.index.name = "filename.42s"
Warning switches can be specified in FGLPROFILE.
fglrun.localization.warnKeyNotFound = boolean
By default, this warning switch is disabled.
If the 42s string file was defined with fglrun.localization.* FGLPROFILE entries, it is considered as mandatory, and the runtime system will raise error -8006 if the file is not found. If the progname.42s and default.42s string files are not found, no error is raised, because these are fallback string resource files.
If a localized string is not defined in one of the compiled string files, the runtime system uses the string identifier as default text.
When a localized string is defined in several compiled string files, the runtime system uses the first string found.
For example, if the string "hello" is defined in program.42s as "hello from program", and in default.42s as "hello from default", the runtime system will use the text "hello from program".
A set of .42s files using the same language and codeset is typically copied in a distribution directory with a name identifying the locale.
/opt/app/resource/strings/en_US.iso8859-1 -- English strings in iso8859-1 code-set /opt/app/resource/strings/fr_FR.iso8859-1 -- French strings in iso8859-1 code-set /opt/app/resource/strings/jp_JP.utf8 -- Japanese strings in utf-8 code-set
$ echo $LC_ALL jp_JP.utf8 $ FGLRESOURCEPATH="$FGLRESOURCEPATH:/opt/app/resource/strings/$LC_ALL" $ export FGLRESOURCEPATH $ echo $FGLRESOURCEPATH /opt/app/forms:/opt/app/resource/strings/jp_JP.utf8
On startup, the mobile app will by default search for localized string files (.42s) in appdir/locale-code, the application sub-directory having the same name as the locale identifier (with language and category/region codes) (for an English-US locale: appdir/en_US). If the 42s files are not found in this sub-directory, the runtime system tries to load the files from a sub-directory with the language identified only (for an English-US locale: appdir/en). Finally, if the string files are not found in locale-specific directories, the files are loaded directly from appdir.
In order to localize your application, you simply need to place your .42s localized string files in the appropriate language sub-directory.
If you want to distinguish language categories (Simplified/Tradition Chinese), or if you want to use different texts according to the territory for the same language (English in USA or Great Britain), create language sub-directories with the exact OS locale identifier:
appdir/en_US/mystrings.42s appdir/en_GB/mystrings.42s appdir/en_CA/mystrings.42s
If the language category or region can be ignored, create language sub-directories with names matching the language identifier only:
appdir/en/mystrings.42s appdir/fr/mystrings.42s appdir/de/mystrings.42s
appdir/mystrings.42s