langPackage
=========
Node.js module for the organization of control of languages in the application and templating of strings.
Installation
npm install langpackage
Usage
var langPackage = ; let langPack = {};langPacken = ;langPackde = ; //push simple phraselangPacken;langPackde; let currentLang = 'en';var result = langPackcurrentLang; //return 'Good day'currentLang = 'de';result = langPackcurrentLang; // return 'Guten Tag' //simple templatelangPacken;result = langPacken; // return 'I have 3 apple.' //template with functionlangPackde;result = langPackde; // return 'Ich habe 1 Apfel.'result = langPackde; // return 'Ich habe 2 Äpfel.' //export dictionary (dictionary does not contain functions)var json = langPacken; //import dictionary (dictionary does not contain functions)langPacken;
API Reference
pushPhrase(keyword, phrase)
Adds phrase to dictionary
- keyword:
String
Phrase keyword. - phrase:
Array
Phrase template. Can contain strings and functions with one parameter. The first element always a string. After the function the next element should be a string.
get(keyword, [args])
Returns the phrase with the arguments added in a template
- keyword:
String
Phrase keyword. - args:
Array
optional
Template arguments.
exportJSON()
Return dictionary as JSON string
- Attention! You can export the dictionary does not contain functions, otherwise an error.
importJSON(json)
Import dictionary from JSON string. Returns import success
- json:
String
Dictionary in JSON. - Attention! You can import the dictionary does not contain functions, otherwise an error.
- Attention! Import will replace the old dictionary.
Dictionary example:
{"hello":["Good day"], "apple":["I have ", " apple."]}
Tests
npm test
Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
License
MIT license