basic-multilang
v0.0.5
Published
Basic implemetation of multilang support for NodeJS
Downloads
1
Readme
basic-multilang
Basic implemetation of multilang support for NodeJS.
Installation
npm install basic-multilang --save
Usage
Include
var I18n = require('basic-multilang');
new I18n(directory, reload = null)
;
Create a instance to render I18n.
Arguments
Name | Type | Description
-------------|------------|-------------
directory
| string
| Translations directory.
reload
| function
| Funcion to load files. If !reload
then will be used require
.
Example
// Option 1
var i18n = new I18n(path.resolve(__dirname, 'i18n'));
// Option 2
var reload = require('require-reload')(require);
var i18n = new I18n(path.resolve(__dirname, 'i18n'), reload);
i81n.setLang(lang)
;
Set language to use.
Arguments
Name | Type | Description
--------|----------|-------------
lang
| string
| Language to set. This will be key to get el translation.
Example
i18n.setLang('es');
i81n.getLang()
;
Return then language to seted.
const lang = i18n.getLang();
i81n.get(key)
;
Return the translation for a specific key.
Arguments
Name | Type | Description
-------|----------|-------------
key
| string
| Key to get translation.
var i18n = new I18n(path.resolve(__dirname, 'i18n'));
i18n.setLang('es');
const translation = i18n.get('mysubdirectory.myfile.myphrasekey');
// in file ./i18n/mysubdirectory/myfile.js[on], get poperty myphrasekey.es.
Troubles
If you have any kind of trouble with it, just let me now by raising an issue on the GitHub issue tracker here:
https://github.com/arondn2/basic-multilang/issues
Also, you can report the orthographic errors in the READMEs files or comments. Sorry for that, English is not my main language.
Tests
npm test
or npm run cover