Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

new-i18n

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

new-i18n

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

  • 3.0.0-5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

new-i18n

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

Changelog

See CHANGELOG.md

Installation

npm install new-i18n

Example

localization/en.json:

{
    "hello_world": "Hello World"
}

localization/pt.json:

{
    "hello_world": "Olá Mundo"
}

index.js:

const { default: I18n } = require('new-i18n');
const i18n = new I18n(__dirname, ['en','pt'], 'en');

console.log('English:', i18n.translate('en', 'hello_world'));
console.log('Portuguese:', i18n.translate('pt', 'hello_world'));

console.log(i18n.translate('en', 'hi', { name: '...' }));
console.log(i18n.translate('pt', 'hi', { name: '...' }));

i18n.update('en', { hi: 'Hello my name is {{name}}!' });
i18n.update('pt', { hi: 'Olá meu nome é {{name}}!' });

console.log(i18n.translate('en', 'hi', { name: '...' }));
console.log(i18n.translate('pt', 'hi', { name: '...' }));

console.log(`I18n languages: ${i18n.languages}`)

Adding variables

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

Updating Varaibles

i18n.update('en', { hi: 'Hello my name is {{name}}!' });
i18n.translate('en', 'hi', { name: '...' }); // 'Hello my name is ...!'

Nesting

localization/en.json:

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

localization/pt.json:

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

index.js:

i18n.translate('en', 'nested.hello_world'); // 'Hello World'
i18n.translate('pt', 'nested.hello_world'); // 'Olá Mundo'

Getting all the languages

i18n.languages; // ['en', 'pt']

FAQs

Package last updated on 28 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc