Grab default options from environment variables
withEnv();
// => { defaultLocale: 'en', locales: ['en', ...], ... };objectenvironment options
Merge provided options with defaults
| Name | Type | Description | |
|---|---|---|---|
| optns={} | object |
provided options | Optional |
| optns.staticCatalog=undefined | object |
static translations object | Optional |
const optns = { locales: [...] };
const options = withDefaults(optns);
// => { locales: ['en', ...], ... };objectmerged options
i18n factory
| Name | Type | Description | |
|---|---|---|---|
| optns={} | object |
valid i18n options | Optional |
| optns.reset=false | boolean |
reset i18n | Optional |
| optns.staticCatalog=undefined | object |
static translations object | Optional |
import { configure } from '@lykmapipo/i18n';
const optns = { .. };
const i18n = configure(optns);
i18n.t('hello'); // => Hello
i18n.t('hello', 'sw'); // => Mamboobjecti18n helpers
Reset i18n internals
import { reset } from '@lykmapipo/i18n';
reset();
// => undefinedobjecti18n helpers
Translates a single phrase and adds it to locales if unknown
| Name | Type | Description | |
|---|---|---|---|
| phrase | string |
localized phrase | |
| locale=en | string |
locale to use in translation or default | Optional |
| optns={} | object |
data to use on parse and substitution | Optional |
import { t } from '@lykmapipo/i18n';
t('hello'); // => Hello
t('hello', 'sw'); // => Mambo
t('greeting', { name: 'John' }); // => Hello John
t('greeting', 'sw', { name: 'John' }); // => Mambo Johnstringtranslated parsed and substituted string
Provides list of translations for a given phrase in each language
| Name | Type | Description | |
|---|---|---|---|
| phrase | string |
localized phrase |
import { l } from '@lykmapipo/i18n';
l('hello');
// => [ 'Hello', 'Mambo' ]stringtranslated parsed and substituted string
Provides hashed list of translations for a given phrase in each language.
| Name | Type | Description | |
|---|---|---|---|
| phrase | string |
localized phrase |
import { h } from '@lykmapipo/i18n';
h('hello');
// => [ { en: 'Hello' }, { sw: 'Mambo'} ]stringtranslated parsed and substituted string
Plurals translation of a single phrase
Note: Singular and plural forms will get added to locales if unknown
| Name | Type | Description | |
|---|---|---|---|
| phrase | string |
localized phrase | |
| locale=en | string |
locale to use in translation or default | Optional |
| count=0 | number |
count to use on parse and substitution | Optional |
import { n } from '@lykmapipo/i18n';
n('You have %s message', 1); // => You have 1 message
n('You have %s message', 'sw', 1); // => Una meseji 1
n('You have %s message', 4); // => You have 4 messages
n('You have %s message', 'sw', 4); // => Una meseji 4stringtranslated parsed and substituted string based on last count parameter
Provide a whole transalation catalog of a given locale
| Name | Type | Description | |
|---|---|---|---|
| locale | string |
locale to obtain catalog for | Optional |
import { catalog } from '@lykmapipo/i18n';
catalog();
// => { en: { ... }, sw: { ... }, ... };
catalog('en');
// => { ... };objecttranslation catalog
Documentation generated with doxdox.