‚̧Novices Performing Miracles
    Wondering what‚Äôs next for npm?Check out our public roadmap! ¬Ľ

    littera

    1.1.0¬†‚Äʬ†Public¬†‚Äʬ†Published

    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

    Install

    npm i littera

    DownloadsWeekly Downloads

    2

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    15.1 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar