A basic and lightweight replacement for Globalize. Store all languages supported by translatewiki.net in a JSON object, accesible as node module or by browser javascript interpret. No dependencies.
npm install languages4translatewikilanguages4translatewiki
=======================
This a enlarger version of languages.js, for supporting all languages of translatewiki.net.
A basic and lightweight replacement for Globalize. Stores ISO 639 language database in a JSON object, accesible as node module or by browser javascript interpret. Without any dependencies.
Features
--------
1. The same file can be use from the server side in nodejs to the client side in javascript browser interpret.
2. Also includes the json file for using in other languages, for example PHP.
3. Supports 330 languages
4. Lightweight, only 11K or 5.9K gzipped.
5. Very basic too, but enough for a lot of projects: only return the ISO 639 language codes of supported languages, the English name, the nativeName and his own direction.
6. Contain a build script which scrap translatewiki page for languages support, minimizes the code with uglify, and compresses it with gzip.
Use
---
From javascript the JSON object is not accesible directly. You must use this public functions:
languages.isValid(langcode): Return boolean value, true if langcode is supported.*
languages.getAllLanguageCode(): Return an array with all the language codes supported.*
languages.getLanguageInfo(langcode): Return object {"name": name of the language in English, "nativeName", "direction"}.
If langcode isn't supported return {}.*
See the test folder for use examples:
``js
// From node the module is accesible with a simple require
var languages = require ('../languages.min.js');
var num_languages = 0;
// languages.getAllLanguageCode() return an array of all ISO 639 language code supported
var langscodes = languages.getAllLanguageCode();
// iterate this array
for (num_languages=0; num_languages
console.log(langscodes[num_languages]);
console.log(" "+JSON.stringify(languages.getLanguageInfo(langscodes[num_languages])));
}
// show the number of languages supported
console.log("Languages supported: "+num_languages);
// test languages.isValid(langcode) function
console.log("¿isValid 'kaka' language code? "+languages.isValid('kaka'));
console.log("¿isValid 'es' language code? "+languages.isValid('es'));
`
`html`
Test languages module (Browser client side)
Build
-----
To built a new version of languages4translatewiki, you need to install these node modules:
`sh``
npm install jsdom
npm install -g uglify-js
And then execute build/build.sh