ttag API
addLocale
addLocale(locale: string, poData: Object)
Register locale translations.
Arguments:
locale: stringLocale name (i.e.:'uk','en')poData: Objectparsed data from a.pofile.
Example:
const poData = {
headers: {
'plural-forms': 'nplurals=2; plural=(n!=1);',
},
translations: {
'': {
test: { msgid: 'test', msgstr: 'test translation' },
},
},
};
addLocale('en', poData);
useLocale
useLocale(locale: string | () => string)
Activates a locale. After setting the locale to be used, all strings marked for translations will be represented by the corresponding translation in the specified locale.
Arguments:
locale: string | () => stringLocale name (i.e:'uk','en') or function that return this locale name
The variant with function argument could be useful to resolve problem with global TTag instance when you use SSR and streaming (Demo)
Example:
useLocale('uk');
// or
useLocale(() => 'uk');
useLocales
useLocales(locales: string[])
If you want to have multiple translations look up locations, you can use this
method. The library will try to resolve translations exactly in the same order as you
specify in the locales argument.
Arguments:
locales: string[]List of locale names (i.e.:'uk','en')
Example:
useLocales(['en_US', 'en']);
setDedent
setDedent(value: bool)
Default: true
Activates or deactivates dedent for multiline translatable strings.
Arguments:
value: boolActivates or deactivates dedent.
Example:
setDedent(false);
setDefaultLang
setDefaultLang(lang: string)
Sets default language that is used in your sources strings. This setting is used for plural forms extraction.
Different language have different plural forms numbers and formulas.
Arguments:
lang: stringISO code for the language. See all available codes here at the GNU gettext manual
Example:
setDefaultLang('uk');