exlib.i18n

This module contains UI internationalization support implementation.

UIString struct provides string container which can be either plain unicode string or id of string resource.

Translation strings are being stored in translation files, consisting of simple key=value pair lines:

STRING_RESOURCE_ID=Translation text 1
ANOTHER_STRING_RESOURCE_ID=Translation text 2

Supports fallback to another translation file (e.g. default language).

If string resource is not found neither in main nor fallback translation files, UNTRANSLATED: RESOURCE_ID will be returned.

String resources must be placed in i18n subdirectory inside one or more resource directories (set using Platform.instance.resourceDirs property on application initialization).

File names must be language code with extension .ini (e.g. en.ini, fr.ini, es.ini)

If several files for the same language are found in (different directories) their content will be merged. It's useful to merge string resources from DLangUI framework with resources of application.

Set interface language using Platform.instance.uiLanguage in UIAppMain during initialization of application settings:

Platform.instance.uiLanguage = "en";
More...

Members

Classes

UIStringTranslator
class UIStringTranslator

UI Strings internationalization translator

Structs

UIString
struct UIString

Container for UI string - either raw value or string resource ID

UIStringCollection
struct UIStringCollection

UIString item collection

Variables

i18n
UIStringTranslator i18n;

Global UI translator object

Detailed Description

Synopsis:

1 import exlib.i18n;
2 
3 // use global i18n object to get translation for string ID
4 dstring translated = i18n.get("STR_FILE_OPEN");
5 // as well, you can specify fallback value - to return if translation is not found
6 dstring translated = i18n.get("STR_FILE_OPEN", "Open..."d);
7 
8 // UIString type can hold either string resource id or dstring raw value.
9 UIString text;
10 
11 // assign resource id as string (will remove dstring value if it was here)
12 text = "ID_FILE_EXIT";
13 // or assign raw value as dstring (will remove id if it was here)
14 text = "some text"d;
15 // assign both resource id and fallback value - to use if string resource is not found
16 text = UIString("ID_FILE_EXIT", "Exit"d);
17 
18 // i18n.get() will automatically be invoked when getting UIString value (e.g. using alias this).
19 dstring translated = text;

Meta

Authors

Vadim Lopatin, coolreader.org@gmail.com

License

Boost License 1.0