itranslator icon indicating copy to clipboard operation
itranslator copied to clipboard

Simple node module to deal with translation in your app

npm version

translator

node module to deal with translation in your app

Install

Using yarn :

yarn add itranslator

Using npm :

npm install itranslator

Usage

const {
  trans,
  setConfig
} = require('itranslator');

//Returns the same string if no configuration provided
trans('en.hello'); // "en.hello" 

//You can put a global configuration at the entry point of your app
setConfig({
  source : {
    en : {
      hello : "hello"
    },
    it : { 
      hello : "bonjourno"
    }
  }
});

trans('en.hello'); // "hello" 
trans('it.hello'); // "bonjourno" 

//It's also possible to override the global configuration if needed
trans('it.hello',{
  vars : new Map().set('name', 'imam'),
  source : {
    it : {
      hello : 'bonjourno %name%'
    }
  }
}); // "bonjourno imam" 

trans('it.hello'); // "bonjourno imam"