tiny-i18n-node
v0.0.2-alpha.3
Published
Tiny module to handle NodeJS i18n
Downloads
538
Maintainers
Readme
tiny-translation-node
The simplest NodeJS i18n module
Install
$ npm install tiny-i18n-node
Usage
First of all, create your lang/*.json
files inside your root folder.
en.json
{
"module": {
"description": "The simplest NodeJS i18n module"
},
"users": {
"welcome": "Welcome, :name!"
}
}
es.json
{
"module": {
"description": "El módulo de internacionalización NodeJS más sencillo"
},
"users": {
"welcome": "¡Bienvenido, :name!"
}
}
br.json
{
"module": {
"description": "O mais simples módulo de internacionalização utilizando NodeJS"
},
"users": {
"welcome": "Bem-vindo, :name!"
}
}
Then use it:
const trans = require('tiny-i18n-node')
trans('module.description') //=> "Tiny module to handle NodeJS i18n"
You get the current location:
trans.getLocale() //=> Default: "en"
Or switch between them:
// Switch to Spanish
trans.setLocale('es')
trans('module.description') //=> "Pequeño módulo para manejar la internacionalización de Node JS"
Set some replacements:
trans('users.welcome', {name: 'John'}) //=> "Welcome, John!"
License
MIT © Alison Monteiro