Text translation framework.
This library aims to facilitate native language support in applications and
libraries written in D. String resources containing natural language text
are read from XML documents, called catalogs, supplied at compile-time.
In source code, string resources are referenced with the strings
interface. The languages to use are configured automatically at the start
of the program based on the running user's environment, before the main
function is entered.
<?xml version="1.0" encoding="utf-8"?> <resources language="primary_catalog_language"> <translation language="translation1"/> <translation language="translation2"/> <translation language="..."/> <string name="id1">text1</string> <string name="id2">text2</string> <string name="...">...</string> </resources>For the primary catalog, the root element's language attribute is required and contains the language used in the primary catalog. Each translation element declares that a translation catalog for the given language is supplied and should be loaded. All language attributes are ISO-639 language codes. Each string element defines a string resource, where the name attribute is the resource identifier, and the element's content is the resource text.
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="id1">text1</string> <string name="id2">text2</string> <string name="...">...</string> </resources>Each string element provides a translation of the string resource with the given identifier. The identifier must match the identifier of a string resource in the primary catalog.
void main() { import std.stdio, i18n.text; // Writes the string resource with the identifier "hello_world" to stdout writeln(strings.hello_world); }
Default encoding for string resources, returned by Strings.opDispatch.
Set version i18n_use_utf32 to use dstring, or version i18n_use_utf16 to use wstring; otherwise uses string (UTF-8).
Get the text for id according to the user's preferred language(s).
id | identifier of string resource (the name attribute) |
S | encoding for returned string, either string, wstring or dstring |
void main() { import std.stdio, i18n.text; writeln(strings.hello_world); // Default encoding writeln(strings.getEncoded!("hello_world", wstring)); // UTF-16 }