Retrieve a translation for a string.
Retrieve a translation for a string with a fixed locale.
Retrieve a translation for a string containing a possible plural with
a fixed locale.
You will almost always want to call _nx
instead so that
you can interpolate the number of items into the strings.
The method _lnp()
combines _ln()
with _lp()
.
You will almost always want to call _npx
instead so that
you can interpolate the number of items into the strings.
The method _lnpx()
brings it all together. It combines _ln()
and
_lp()and
_lx()`.
Translate a string with a plural expression with placeholders into a fixed locale.
Translate a string with a context with a fixed locale.
The method _lpx()
combines _lp()
with _lx()
.
Translate a string with placeholders for a fixed locale. The placeholders should be wrapped into curly braces and must match the regular expression "[_a-zA-Z][_a-zA-Z0-9]*".
Retrieve a translation for a string containing a possible plural.
You will almost always want to call _nx
instead so that
you can interpolate the number of items into the strings.
The method _np()
combines _n()
with _p()
.
You will almost always want to call _npx
instead so that
you can interpolate the number of items into the strings.
The method _npx()
brings it all together. It combines _n()
and
_p()and
_x()`.
Translate a string with a plural expression with placeholders.
Translate a string with a context.
The method _px()
combines _p()
with _x()
.
Translate a string with placeholders. The placeholders should be wrapped into curly braces and must match the regular expression "[_a-zA-Z][_a-zA-Z0-9]*".
Instantiate a Textdomain object. Textdomain objects are singletons for each textdomain identifier.
Get the catalog format in use.
one of 'json' or 'mo' (default is 'json')
Set the catalog format to use.
one of 'json' or 'mo'
one of 'json' or 'mo' (default is 'json')
Query the locale in use.
For the web you can use all valid language identifier tags that BCP47 allows (and actually a lot more). The tag is always used unmodified.
For server environments, the locale identifier has to match the following scheme:
ll_CC.charset\@modifier
ll
is the two- or three-letter language code.CC
is the optional two-letter country code.charset
is an optional character set (letters, digits, and the hyphen).modifier
is an optional variant (letters and digits).The language code is always converted to lowercase, the country code is converted to uppercase, variant and charset are used as is.
the locale in use
Change the locale.
For the web you can use all valid language identifier tags that BCP47 allows (and actually a lot more). The tag is always used unmodified.
For server environments, the locale identifier has to match the following scheme:
ll_CC.charset\@modifier
ll
is the two- or three-letter language code.CC
is the optional two-letter country code.charset
is an optional character set (letters, digits, and the hyphen).modifier
is an optional variant (letters and digits).The language code is always converted to lowercase, the country code is converted to uppercase, variant and charset are used as is.
the locale identifier
the locale in use
Does the same as the static method N_()
.
the message id
the original string
Same as N_()
but with context.
the message id
the original string
Same as N_()
but with context and placeholder expansion.
the message id
a dictionary of placeholders
the original string with placeholders expanded
Same as N_()
but with placeholder expansion.
the message id
a dictionary of placeholders
the original string with placeholders expanded
Bind a textdomain to a certain path or queries the path that a
textdomain is bound to. The catalog file will be searched
in ${path}/locale/LC_MESSAGES/${domainname}.EXT
.
Alternatively, you can pass a LocaleContainer
that holds the
catalogs in memory.
the base path or LocaleContainer
for this textdomain
Resolve a textdomain, i.e. load the LocaleContainer for this domain and all of its dependencies for the currently selected locale or the locale specified.
The promise will always resolve. If no catalog was found, an empty catalog will be returned that is still usable.
an optional locale identifier, defaults to Textdomain.locale
a promise for a Catalog that will always resolve.
A textdomain is an identifier for your application or library. It is the basename of your translation files which are either TEXTDOMAIN.json or TEXTDOMAIN.mo, depending on the format you have chosen.
FIXME! This should be a getter!
the textdomain
A no-op method for string marking.
Sometimes you want to mark strings for translation but do not actually want to translate them, at least not at the time of their definition. This is often the case, when you have to preserve the original string.
Take this example:
orangeColors = [gtx.N_('coral'), gtx.N_('tomato'), gtx.N_('orangered'),
gtx.N_('gold'), gtx.N_('orange'), gtx.N_('darkorange')]
These are standard CSS colors, and you cannot translate them inside CSS styles. But for presentation you may want to translate them later:
console.log(gtx._x("The css color '{color}' is {translated}.",
{
color: orangeColors[2],
translated: gtx._(orangeColors[2]),
}
)
);
In other words: The method just marks strings for translation, so that
the extractor esgettext-xgettext
finds them but it does not actually
translate anything.
Similar methods are available for other cases (with placeholder expansion, context, or both). They are not available for plural methods because that would not make sense.
Note that all of these methods are also available as instance methods.
the message id
the original string
Does the same as the static method N_p()
.
the message id
the original string with placeholders expanded
Does the same as the static method N_px()
.
the message id
a dictionary of placeholders
the original string with placeholders expanded
Does the same as the static method N_x()
.
the message id
a dictionary of placeholders
the original string with placeholders expanded
Delete all existing singletons. This method should usually be called only, when you want to free memory.
This method is used for testing. Do not use it yourself!
Select one of the supported locales from a list of locales accepted by the user.
the list of locales supported by the application
the list of locales accepted by the user
If called with just one argument, then the list of requested locales is determined by calling Textdomain.userLocales.
the negotiated locale or 'C' if not possible.
Queries the user's preferred locales. On the server it queries the
environment variables LANGUAGE
, LC_ALL
, LANG
, and LC_MESSAGES
(in that order). In the browser, it parses it checks the user preferences
in the variables navigator.languages
, navigator.language
,
navigator.userLanguage
, navigator.browserLanguage
, and
navigator.systemLanguage
.
the set of locales in order of preference
Added in @runtime 0.1.0.
Generated using TypeDoc
A Textdomain is a container for an esgettext configuration and all loaded LocaleContainer for the textual domain selected.
The actual translation methods have quite funny names like
_()
or_x()
. The purpose of this naming convention is to make the internationalization of your programs as little obtrusive as possible. Most of the times you just have to exchangedoSomething('Hello, world!');
with
doSomething(gtx._('Hello, world!'));
Besides, depending on the string extractor you are using, it may be useful that the method names do not collide with method names from other packages.