Skip to content

Latest commit

 

History

History
309 lines (134 loc) · 4.46 KB

DOCUMENTATION.md

File metadata and controls

309 lines (134 loc) · 4.46 KB

withEnv()

Grab default options from environment variables

Examples
withEnv();
// => { defaultLocale: 'en', locales: ['en', ...], ... };
Returns
  • object environment options

withDefaults([optns={}])

Merge provided options with defaults

Parameters
Name Type Description
optns={} object provided options Optional
optns.staticCatalog=undefined object static translations object Optional
Examples
const optns = { locales: [...] };
const options = withDefaults(optns);
// => { locales: ['en', ...], ... };
Returns
  • object merged options

configure([optns={}])

i18n factory

Parameters
Name Type Description
optns={} object valid i18n options Optional
optns.reset=false boolean reset i18n Optional
optns.staticCatalog=undefined object static translations object Optional
Examples
import { configure } from '@lykmapipo/i18n';

const optns = { .. };
const i18n = configure(optns);

i18n.t('hello'); // => Hello
i18n.t('hello', 'sw'); // => Mambo
Returns
  • object i18n helpers

reset()

Reset i18n internals

Examples
import { reset } from '@lykmapipo/i18n';

reset();
// => undefined
Returns
  • object i18n helpers

t(phrase[, locale=en, optns={}])

Translates a single phrase and adds it to locales if unknown

Parameters
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
Examples
import { t } from '@lykmapipo/i18n';

t('hello'); // => Hello
t('hello', 'sw'); // => Mambo
t('greeting', { name: 'John' }); // => Hello John
t('greeting', 'sw', { name: 'John' }); // => Mambo John
Returns
  • string translated parsed and substituted string

l(phrase)

Provides list of translations for a given phrase in each language

Parameters
Name Type Description
phrase string localized phrase  
Examples
import { l } from '@lykmapipo/i18n';

l('hello');
// => [ 'Hello', 'Mambo' ]
Returns
  • string translated parsed and substituted string

h(phrase)

Provides hashed list of translations for a given phrase in each language.

Parameters
Name Type Description
phrase string localized phrase  
Examples
import { h } from '@lykmapipo/i18n';

h('hello');
// => [ { en: 'Hello' }, { sw: 'Mambo'} ]
Returns
  • string translated parsed and substituted string

n(phrase[, locale=en, count=0])

Plurals translation of a single phrase Note: Singular and plural forms will get added to locales if unknown

Parameters
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
Examples
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 4
Returns
  • string translated parsed and substituted string based on last count parameter

catalog([locale])

Provide a whole transalation catalog of a given locale

Parameters
Name Type Description
locale string locale to obtain catalog for Optional
Examples
import { catalog } from '@lykmapipo/i18n';

catalog();
// => { en: { ... }, sw: { ... }, ... };

catalog('en');
// => { ... };
Returns
  • object translation catalog

Documentation generated with doxdox.