A basic and lightweight replacement for Globalize. Store ISO 639-1 language database in a JSON object, accesible as node module or by browser javascript interpret. No dependencies.
npm install languageslanguages.js
============
A basic and lightweight replacement for Globalize. Store ISO 639-1 language database in a JSON object, accesible as node module or by browser javascript interpret. No dependencies.
Features
--------
1. The same file can be use from server side in nodejs to client side in javascript browser interpret.
2. Also includes the json file for using in other languages, for example PHP.
3. Support 138 languages
4. Very lightweight, only 6.7K or 3.7K gzipped.
5. Very basic too, but enough for a lot of project: only return the ISO 639-1 language codes of languages supported, the English name, the nativeName and his direction.
Use
---
From javascript the JSON object isn't 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-1 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)