Skip to content

Latest commit

 

History

History
53 lines (45 loc) · 1009 Bytes

README.md

File metadata and controls

53 lines (45 loc) · 1009 Bytes

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"