https://github.com/gucheen/i18n-render
tiny i18n solution for tiny projects.
Design
The i18n-render's structure is key -> translation dictionary. While the translation dict is locale -> text.
In short, i18n-render take a key to get the translation dict, then get translated text with locale.
Source Configuration
;
// or
;
Usage
  这是一段默认的中文
  
  
// import I18nRender from 'i18n-render';
;
'DOMContentLoaded',;
API
class I18nRender constructor
| parameter | value | description | 
|---|---|---|
| source | Object<string, string> | Translation dictionaries for various languages | 
| locale | string | Set locale directly instead of auto detect | 
| pageTextLocale | string | If your page already has text in a certain language, setting this parameter can prevent the re-rendering of this language, and you do not need to provide translation of this language. | 
| fullLangTag | boolean | I18n-render uses a short locale tag by default, such as en,fr,de,jp. However, languages can distinguish regions, such aszh-CNandzh-HK, which need two different translation versions. In this case,fullLangTag: truecan be set, and the configuration items of the language will become complete modes, such asen-USandzh-CN | 
getLocale() => string
Get current locale of i18n-render.
setLocale()
Change to another locale manualy.
- locale stringthe target locale
- persist boolean$1,falsestore locale to localStorage, next time i18n-render will init with this locale
- rerender boolean$2,truere-render page text after change locale
getText() => string
Get the i18n text of the target text with key
- key stringthe key of text in translation dict
- locale string$3the locale want to use, default to current locale of i18n-render
- fallback string$4this fallback text will be used if the target statement does not have a translation dictionary configured or if there is no corresponding language setting.
render()
Render all i18n-render elements in page.
Browser support
The latest version of Chrome, Firefox, Edge, and Safari.