Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/alisonmonteiro/tiny-i18n-node
- Owner: alisonmonteiro
- License: mit
- Created: 2019-06-17T17:10:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T00:53:55.000Z (almost 2 years ago)
- Last Synced: 2023-12-26T18:11:31.751Z (11 months ago)
- Topics: dot-notation, i18n, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 913 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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/)