Giter VIP home page Giter VIP logo

i.js's Introduction

Tiny utility to implement localization in JavaScript (L10N), supporting only scoped translations; and simple templates.

Features

  • Supports scoped translations
  • Supports simple templates with mustaches {{ }}
  • Enables the implementation of text localization
  • Supports NodeJs and amd
  • Minified it weighs only 1.8 KB

More complex solutions

I.js is meant to be as simple and short as possible, and to support only scoped translations. Users who need more complex solutions (e.g. with support for pluralization; currencies; dates management), should look instead at other libraries (internationalization frameworks):

For a comparison with i18n-js library, please refer to the dedicated wiki page;

How to use

Either install using npm:

npm install ilocale

Or download one of these two files:

ES6 Example

If I.js is installed using npm package:

import I from "ilocale"

I.regional = {
  "en": {
    "voc": {
      "Hi": "Hi"
    }
  }
}

I.setLocale("en");
I.t("voc.Hi"); // --> "Hi"

Examples

The following example shows how to work with scoped translations, using I.js:

(function () {

  //set the locale information:
  I.regional = {
    "en": {
      "voc": {
        "Hi": "Hi"
      }
    },
    "it": {
      "voc": {
        "Hi": "Ciao"
      }
    },
    "pl": {
      "voc": {
        "Hi": "Cześć"
      }
    }
  };

  I.setLocale("en");
  I.t("voc.Hi"); // --> "Hi"

  I.setLocale("it");
  I.t("voc.Hi"); // --> "Ciao"

  I.setLocale("pl");
  I.t("voc.Hi"); // --> "Cześć"

})();

The following example shows how to use simple templates:

(function () {

  //set the locale information:
  I.regional = {
    "en": {
      "voc": {
        "HelloName": "Hello, {{name}}!"
      }
    },
    "it": {
       "voc": {
         "HelloName": "Ciao, {{name}}!"
       }
    }
  };

  I.setLocale("en");
  I.t("voc.HelloName"); // --> "Hello, {{name}}!"
  I.t("voc.HelloName", {
    name: "Edyta" // e.g. user.name
  }); // --> "Hello, Edyta!"

  I.setLocale("it");
  I.t("voc.HelloName"); // --> "Ciao, {{name}}!"
  I.t("voc.HelloName", {
    name: "Edyta" // e.g. user.name
  }); // --> "Ciao, Edyta!"

})();

How to organize the locale files

Please refer to the dedicated wiki page.

Examples in other repositories

The following repositories contain examples of internationalization implemented using I.js:

Live demos:

Notes

When setting a locale using the function setLocale; a class to the document.body is also added accordingly.

i.js's People

Contributors

robertoprevato avatar

Stargazers

 avatar 蛮吉是魁拔 avatar Matt Zimmermann avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.