new-i18n
new-i18n is a simple and easy to use internationalization library.
Changelog
See CHANGELOG.md
Installation
npm install new-i18n
Example
There's a full working example here
localization/en.json
:
{
"hello_world": "Hello World"
}
localization/pt.json
:
{
"hello_world": "Olá Mundo"
}
index.js
:
const newI18n = require('new-i18n');
const i18n = newI18n('./localization', ['en', 'pt']);
i18n('en', 'hello_world');
i18n('pt', 'hello_world');
Adding variables
{
"hi": "Hi {{name}}!"
}
i18n('en', 'hi', { name: '...' });
Updating Varaibles
i18n.update('en', { hi: 'Hello {{name}}!' });
i18n('en', 'hi', { name: '...' });
Nesting
localization/en.json
:
{
"nested": {
"hello_world": "Hello World"
}
}
localization/pt.json
:
{
"nested": {
"hello_world": "Olá Mundo"
}
}
index.js
:
i18n('en', 'nested.hello_world');
i18n('pt', 'nested.hello_world');
Getting all the languages
i18n.languages;