Skip to content
new-i18n is a simple and easy to use internationalization library.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc.json
.gitignore
.npmignore
LICENSE
README.md
_config.yml
i18n.js
index.js
package-lock.json
package.json

README.md

new-i18n

new-i18n is a simple and easy to use internationalization library.

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']);

console.log('English:', i18n('en', 'hello_world')); // 'Hello World'
console.log('Portuguese:', i18n('pt', 'hello_world')); // 'Olá Mundo'

Adding variables

{
    "hi": "Hi {{name}}!"
}
console.log(i18n('en', 'hi', { name: '...' })); // 'Hi ...!'

Updating Varaibles

i18n.update('en', { hi: 'Hello {{name}}!' });
console.log(i18n('en', 'hi', { name: '...' })); // 'Hhello ...!'

Nesting

localization/en.json:

{
    "nested": {
        "hello_world": "Hello World"
    }
}

localization/pt.json:

{
    "nested": {
        "hello_world": "Olá Mundo"
    }
}

index.js:

const newI18n = require('new-i18n');
const i18n = newI18n('./localization', ['en', 'pt']);

console.log('English:', i18n('en', 'nested.hello_world')); // 'Hello World'
console.log('Portuguese:', i18n('pt', 'nested.hello_world')); // 'Olá Mundo'

Getting all the languages

const newI18n = require('new-i18n');
const i18n = newI18n('./localization', ['en', 'pt']);

console.log(i18n.languages); // ['en', 'pt']
You can’t perform that action at this time.