No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
YouTwitFace f30d428c13 Change version 1 month ago
test Add fallback parameter 1 month ago
.eslintrc.json Add eslint 9 months ago
.gitignore Add tests 9 months ago
.npmignore Add eslint 9 months ago
README.md Add nesting example to readme 9 months ago
_config.yml Set theme jekyll-theme-cayman 1 year ago
index.js Add fallback parameter 1 month ago
package-lock.json Change version 1 month ago
package.json Change version 1 month ago

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 ...'

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