Littera
🌐 Lightweight library making multilingualism easier.
Install
Use npm install littera
or clone/download the repository.
Examples
The basic concept is that you load an object with translations for each language and then just get a string with the right translation returned adequate to the active language.
Most basic example
; // Object containing translations for each language and key.const translations = en_US: "unique.example": "Example" pl_PL: "unique.example": "Przykład" de_DE: "unique.example": "Beispiel" ; // Create an instance of Littera and load the translations.const _littera = translations; // Set the active language to German (de_DE)_littera; // Get the right translation for the active language using a key.const translation = _littera;console; // Returns => Beispiel
Stacked languages example
; // Object containing translations for each language and key with stacked languages.const translations = "unique.example": en_US: "Example" pl_PL: "Przykład" de_DE: "Beispiel" // Create an instance of Littera and load the translations.const _littera = translations stackLanguages: true ; // !** { stackLanguages: true } **! // Set the active language to German (de_DE)_littera; // Get the right translation for the active language using a key.const translation = _littera;console; // Returns => Beispiel
Give it a try on codesandbox
Instance
new Littera(translations, options)
You can pass two object arguments translations
and options
.
Options default
{
stackLanguages: false // Use the stacked type of translations.
}
Translations example
{
en_US: {
"unique.example": "Example"
},
pl_PL: {
"unique.example": "Przykład"
},
de_DE: {
"unique.example": "Beispiel"
}
}
or for stacked languages
{
"unique.example": {
en_US: "Example",
pl_PL: "Przykład",
de_DE: "Beispiel"
}
}
Note: You have to set stackLanguages
to true
in options.
Build instructions
After cloning the repo, install all dependencies using npm install
.
Build the docs:
npm run docs
Build the coverage:
npm run coverage
Test the library:
npm test
API
Here comes the geeky part - documentation.
License
Copyright (c) 2018 Mike Eling