Need private packages and team management tools?Check out npm Teams »

new-i18n

1.4.0 • Public • Published

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

Keywords

none

Install

npm i new-i18n

DownloadsWeekly Downloads

6

Version

1.4.0

License

ISC

Unpacked Size

5.94 kB

Total Files

5

Last publish

Collaborators

  • avatar