Localization.js
Javascript platform for localization and globalization of documents, web pages, web applications et cetra.
Localization.js uses JSON-documents to store translations. A typical file structure of an app using Localization.js would be:
locale/
config.json
en-us/
login.json
no-nb/
login.json
app.js
Usage
localization.js is rather lightweight and easy to setup.
- Create a new instance
var lang = new Localization();
- Initialize the instance
Localization.initialize(config_path, completedCallback);
- Set locale
lang.setLocale(language);
- Load modules
lang.loadModule(module_filename, callback);
- Start processing text
lang.processContent(data, variableArray);
For more, please see the example of usage (below).
Example of usage
The following example is from one of my hybrid web apps.
app.js
var lang = ;lang;
./locale/config.json (localization.js configuration file)
{ "supported_locales": ["no-nb", "en-us"]}
./locale/en-us/login.json (English American language file)
{ "title": "login", "content": { "login_title": "Login", "login_email_placeholder": "E-mail", "login_password_placeholder": "Password", "login_button_text": "Login", "login_not_a_member_text": "Not a member?", "login_sign_up": "Sign up" }}
./locale/no-nb/login.json (Norwegian language file)
{ "title": "login", "content": { "login_title": "Innlogging", "login_email_placeholder": "E-post", "login_password_placeholder": "Passord", "login_button_text": "Logg inn", "login_not_a_member_text": "Ikke medlem?", "login_sign_up": "Opprett bruker" }}
License
MIT License
Copyright (c) 2016 Erlend Ellingsen
See LICENSE
-file.