1.1.0 • Published 5 years ago

littera v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Littera

🌐 Lightweight library making multilingualism easier.

Travis (.com) npm npm bundle size (minified) npm Gitter

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

import Littera from "littera";

// 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 = new Littera(translations);

// Set the active language to German (de_DE)
_littera.setLanguage("de_DE");

// Get the right translation for the active language using a key.
const translation = _littera.translate("unique.example");
console.log(translation); // Returns => Beispiel

Stacked languages example

import Littera from 'littera';

// 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 = new Littera(translations, { stackLanguages: true }); // !** { stackLanguages: true } **!

// Set the active language to German (de_DE)
_littera.setLanguage("de_DE");

// Get the right translation for the active language using a key.
const translation = _littera.translate("unique.example");
console.log(translation); // Returns => Beispiel

Give it a try on codesandbox

Code Sandbox

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

MIT License

Copyright (c) 2018 Mike Eling

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago