language-manager
The most flexible version of multi-language management. Manages language resources. Makes it easy to switch between different language sources.
Install
You must first set up nodejs from https://nodejs.org
$ npm i -g npm
▀ ╢█████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
$ npm i --save language-manager
▀ ╢█████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
Add Resource
Place the file containing the source language definitions in a folder. For example, "tests/resource".
example.com/ # → Root folder for the project
└── tests/ # → Tests folder
└── resource/ # → Resource Folder .setPath('tests/resource')
└── json/ # → Resource Type Folder .setType(LanguageManager.ResourceType.Json)
├── en-us.json # → Resource language.extention English United States
└── tr-tr.json # → Resource language.extention Turkish Turkey
Sample Resource File
en-us.json
{
"root": {
"data": [
{
"type": "string",
"name": "app.name",
"value": "Language Manager"
},
{
"type": "string",
"name": "words.ok",
"value": "Okay"
}
]
}
}
tr-tr.json
{
"root": {
"data": [
{
"type": "string",
"name": "app.name",
"value": "Dil Yöneticisi"
},
{
"type": "string",
"name": "words.ok",
"value": "Tamam"
}
]
}
}
Usage
main.js
var LanguageManager = require('language-manager')
var l = new LanguageManager()
.setType(LanguageManager.ResourceType.Json)
.setPath('tests/resource')
.setLang('en-us')
var expected = 'Language Manager'
var actual = l
.Val('app.name')
console.log(`${l.Lang} : ${actual}`)
Try
$ node main
en-us : Language Manager
Change Language
.
..
...
l.setLang('tr-tr')
expected = 'Dil Yöneticisi'
actual = l
.Val('app.name')
console.log(`${l.Lang} : ${actual}`)
tr-tr : Dil Yöneticisi
Test
$ npm run test
> node tests
Simple Test Tool
==================================================
Is the instance initialized?
Success
--------------------------------------------------
Get resource item with name. Simple Zero Configure?
Success
--------------------------------------------------
Get resource item with name. Zero Configure?
Success
--------------------------------------------------
Get resource item with name. Full Configure?
Success
--------------------------------------------------
Get resource item with name. Full Configure TR?
Success
--------------------------------------------------
Pipelines