Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alisonmonteiro/tiny-i18n-node

The simplest NodeJS i18n module
https://github.com/alisonmonteiro/tiny-i18n-node

dot-notation i18n javascript nodejs

Last synced: about 1 month ago
JSON representation

The simplest NodeJS i18n module

Awesome Lists containing this project

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.

See some examples

en.json

```json
{
"module": {
"description": "The simplest NodeJS i18n module"
},
"users": {
"welcome": "Welcome, :name!"
}
}
```

es.json
```json
{
"module": {
"description": "El módulo de internacionalización NodeJS más sencillo"
},
"users": {
"welcome": "¡Bienvenido, :name!"
}
}
```

br.json
```json
{
"module": {
"description": "O mais simples módulo de internacionalização utilizando NodeJS"
},
"users": {
"welcome": "Bem-vindo, :name!"
}
}
```

Then use it:

```javascript
const trans = require('tiny-i18n-node')

trans('module.description') //=> "Tiny module to handle NodeJS i18n"
```

You get the current location:

```javascript
trans.getLocale() //=> Default: "en"
```

Or switch between them:

```javascript
// Switch to Spanish
trans.setLocale('es')
trans('module.description') //=> "Pequeño módulo para manejar la internacionalización de Node JS"
```

Set some replacements:

```javascript
trans('users.welcome', {name: 'John'}) //=> "Welcome, John!"
```

## License

MIT © [Alison Monteiro](https://alisonmonteiro.com.br/)