const i18nService = require('catbee-i18n');
i18nService.register(serviceLocator);
const i18n = serviceLocator.resolve('i18n');
_t (str, ctx)
- Simple translate_pt (context, str, ctx)
- Simple translate with context_nt (...plurals, num, ctx),
- Translate with plural form_npt (context, ...plurals, num, ctx)
- Translate with plural form and context
ctx
- js object with translates l10n
(name cofiguring with config) property and other properties for replace ${var}
in string by var
variable in ctx
plurals
- plural forms of your application default language
const ctx = {
l10n: {
"": {
"nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)"
},
"Your name ${var.value}": [ null, "Vaše jméno ${var.value}"],
},
var: {
value: '1'
}
};
i18n._t('Your name ${var.value}', ctx) // -> Vaše jméno 1
Service get config
from serviceLocator and use config.i18n
property.
config = { // default config
i18n: {
// po2json default glue symbol to concat context and str
glue: '\u0004',
// plural form for your application default language
plural: 'nplurals=1; plural=0;',
// name of property with po2json object in ctx object
context: 'l10n'
}
};
All errors in i18n methods will be emitted to catbee eventBus:
eventBus.emit('error', error);