A module for globalization
npm install anytv-i18nA module for app internationalization
``sh`
npm install anytv-i18n@latest --save
Simple example:
`js
'use strict';
const i18n = require('anytv-18n');
i18n.configure({
languages_url: 'http://translations.myapp.com/:project/languages',
translations_url: 'http://translations.myapp.com/:project/:lang.json',
locale_dir: path.resolve('translations'),
default: 'en',
debug: true
});
i18n.use('freedom_dashboard')
.load()
.then(() => {
// function to call when everything is loaded
i18n.trans('zh_TW', 'greetings', {
name: 'Raven!'
});
i18n.trans('non_existent_key'); // empty string
})
.catch(() => {
// function to call when there's an error
});
`
* languages_url url for getting all available languages in json. :project will be replaced by the project you're using. Exact JSON format:`json`
{
"data": {
"languages": [
"en",
"zh",
"zh_TW"
]
}
}translation_url
* url for getting json translations. :project will be replaced by the project you're using. :lang will be replaced by the language you're using. Exact format:`json`
{
"greetings": "你好 :name",
...
}
* locale_dir directory where the translations will be cached. should be an absolute path with a trailing backslach. example: /home/user/my-app/translations/debug
* set to true if you want to debuglogger
* replaces the default logger
> note: Only Winston-like loggers are accepted
Install the tools needed:
`sh`
npm install grunt -g
npm install --dev
To compile the ES6 source code to ES5:
`sh`
grunt
To generate the docs:
`sh`
esdoc -c ./esdoc.json
`sh`
npm test
`sh``
npm run coverage
Then open coverage/lcov-report/index.html.
MIT