Localization and Language

Trial includes a simple but effective localisation system. To use it, you should have a lang directory in your project root, and a subdirectory within for each language supported. The languages should follow the standard ISO 3-letter language codes.

Listing available languages works with languages, and a specific language can be loaded with load-language. A "language" itself is simply a hash table that typically associates symbols with strings of language-specific text.

You can access such an entry with language-string, or with the shorthand @ macro. If your string needs interpolation, then it can be written as a format directive string, and interpolated with @format or @formats.

If you programmatically set language-string, you can serialise the table out via save-language. To react to changes to the language dictionary, whether by setting or via load-language, you can define a hook via define-language-change-hook.

Note that the values do not have to be strings. Sometimes it can be useful to stuff a list of choices under a single key, for instance. Trial's system does not care, and leaves it up to you to manage the data appropriately.

The base "language" is stored in each language-dir as a collection of files with the extension .sexp. The files consist of alternating keys and values:

player-name "Yukari"
npc-names ("Frank" "Tim" "Alex")

etc. You may also of course store other language-specific files such as dialogue scripts and so forth in the language specific directory.

Loading the special language :system will query the current system for the native locale and try to load a language matching that locale. Loading any language will try to load the language under any alternate codes and names, and if that fails, it'll try to load eng and if that fails, the first entry of languages.