dtext

Module provides functions to handle localization. Translated string is searched in special files with .lang extention by exact matching with original string. * Lang files are loaded in memory at program start up from current directory. Additional localizations can be loaded with loadLocaleFile function. *

Members

Aliases

_
alias _ = getdtext

Short name for getdtext

Functions

defaultLocale
void defaultLocale(string locale)

Setups current locale name. If empty string is passed to getdtext then default locale will be taken. *

defaultLocale
string defaultLocale()

Returns current locale name. If empty string is passed to getdtext then default locale will be taken.

getdtext
string getdtext(string s, string locale = "")

Returns translated string s for specified locale. If locale is empty default locale will be taken. If locale name is equal to base locale s string is returned without modification. * Localization strings are taken from special files previosly loaded into memory. * If string s isn't persists in locale strings it will be put into fuzzy text map. Fuzzy strings is saved in separate file for each locale to be translated later. *

loadLocaleFile
void loadLocaleFile(string name)

Manuall loads localization file with name. May be usefull to load localization during program execution. *

Manifest constants

BASE_LOCALE
enum BASE_LOCALE;

Special locale that doesn't have own locale file. System won't create additional information (fuzzy file or locale map).

LOCALE_EXTENTION
enum LOCALE_EXTENTION;

File extention which will be searched in current directory to load locale information.

Examples

1     import std.stdio, std.opt, dtext;
2 *
3     void main(string[] args) 
4     {
5         string locale;
6         getopt(args,
7             "l|lang", &locale);
8 *
9         defaultLocale = locale;
10 *
11         writeln(_("Hello, world!")); \\ or use getdtext instead _
12     }

* If text for translation cannot be found in specified locale name, the text will be saved and written down to a special fuzzy texts file at program shutdown. That should help to add new localization fast and without program recompilation. * TODO: <ul> <li>Load localization files on demand;</li> <li>Add ability to unload unused locales.</li> </ul>

Meta