tiny-i18n
Tiny yet useful i18n library.
API
setDictionary
(dict: object, lang: string = getCurrentLanguage()) => object
Set dictionary of lang
.
NOTE: language field is non-case sensitivity.
'zh-CN' has same effect with 'zh-cn'
extendDictionary
(dict: object, lang: string = getCurrentLanguage()) => object
Extend dictionary of lang
.
getWord(key: string, lang: string = getCurrentLanguage())
Get raw word (untranslated) of key
in lang
language environment.
=== 'OK ${1}'
setLanguage(lang: string)
Set current language.
getDictionary: (lang: string = getCurrentLanguage()) => object
const dict = cancel: 'Cancel' confirm: 'OK ${1}' === dict
getCurrentLanguage: () => string
Note: tiny-i18n use isomorphic-language to set current language at first time
i18n: (key: string ...args: string[]) => string
Get translated words in current language.
=== 'zh-CN' === 'Cancel' === 'OK ,Cuttle'
createIsolateI18n()
NOTE: It's useful for create the internal independent i18n environment
const createIsolateI18n setDictionary i18n = tinyI18n === 'Cancel' // true const i = i // throws error// It should be call `i.setDictionary(...)` firstly.
Examples
const tinyI18n = const setDictionary getDictionary i18n setLanguage = tinyI18n