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.

loadLocaleFile
void loadLocaleFile(string name)

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

main
void main(string[] args)
Undocumented in source. Be warned that the author may not have intended to support it.

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

import std.stdio, std.opt, dtext;

void main(string[] args) 
{
    string locale;
    getopt(args,
        "l|lang", &locale);

    defaultLocale = locale;

    writeln(_("Hello, world!")); \\ or use getdtext instead _
}

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