dlangui.core.i18n
This module contains internationalization support implementation.Translation files contain of simple key=value pair lines.
STRING_RESOURCE_ID=Translation text.
Supports fallback to another translation file (e.g. default language).
Synopsis:
import dlangui.core.i18n; // use global i18n object to get translation for string ID dstring translated = i18n.get("STR_FILE_OPEN"); // UIString type can hold either string resource id or dstring raw value. UIString text; // assign resource id as string text = "ID_FILE_EXIT"; // or assign raw value as dstring text = "some text"d; // i18n.get() will automatically be invoked when getting UIString value (e.g. using alias this). dstring translated = text;
License:
Boost License 1.0
Authors:
Vadim Lopatin, coolreader.org@gmail.com
- struct UIString;
- container for UI string - either raw value or string resource ID
- this(string id);
- create string with i18n resource id
- this(dstring value);
- create string with raw value
- const @property dstring value();
- get value (either raw or translated by id)
- @property void value(dstring newValue);
- set raw value
- ref UIString opAssign(dstring rawValue);
- assign raw value
- ref UIString opAssign(string ID);
- assign ID
- struct UIStringCollection;
- UIString item collection.
- @property int length();
- returns number of items
- UIString[] opIndex();
- slice
- UIString[] opSlice();
- slice
- UIString[] opSlice(size_t start, size_t end);
- slice
- UIString opIndex(size_t index);
- read item by index
- UIString opIndexAssign(UIString value, size_t index);
- modify item by index
- dstring get(size_t index);
- return unicode string for item by index
- void opAssign(ref UIStringCollection items);
- Assign UIStringCollection
- void addAll(ref UIStringCollection items);
- Append UIStringCollection
- void opAssign(string[] items);
- Assign array of string resource IDs
- void addAll(string[] items);
- Append array of string resource IDs
- void opAssign(dstring[] items);
- Assign array of unicode strings
- void addAll(dstring[] items);
- Append array of unicode strings
- void clear();
- remove all items
- void add(string item, int index = -1);
- Insert resource id item into specified position
- void add(dstring item, int index = -1);
- Insert unicode string item into specified position
- void add(UIString item, int index = -1);
- Insert UIString item into specified position
- void remove(int index);
- Remove item with specified index
- int indexOf(dstring str);
- Return index of first item with specified text or -1 if not found.
- int indexOf(string strId);
- Return index of first item with specified string resource id or -1 if not found.
- int indexOf(UIString str);
- Return index of first item with specified string or -1 if not found.
- class UIStringTranslator;
- UI Strings internationalization translator.
- shared void findTranslationsDir(string[] dirs...);
- looks for i18n directory inside one of passed dirs, and uses first found as directory to read i18n files from
- shared string[] convertResourcePaths(string filename);
- convert resource path - append resource dir if necessary
- shared bool load(string mainFilename, string fallbackFilename = null);
- load translation file(s)
- shared dstring get(string id);
- translate string ID to string (returns "UNTRANSLATED: id" for missing values)
- UIStringTranslator i18n;
- Global translator object.