Small internationalization module to localize strings in JavaScript
Download or clone the repo to get the i18n.js file, add it to your project and create a reference to it your bundles or pages.
the values are case sensitive test is not the same as Test
Takes as optional argument the culture, if no argument is passed it returns all the resources
Throws an exception if the argument is not a string
Returns the collection of resources as a collection of Cultures which each has a collection of key value pairs with the localized strings
bitI18N.getAll();
bitI18N.getAll('es');
bitI18N.getAll('es-MX');
Takes as arguments:
- the key of the value to be found
- the culture of the value to be found (OPTIONAL), If the culture is not passed as argument, it will take the default browser culture
Throws an exception if:
- the argument key is not a string, is null or undefined
- the argument culture is not a string, is null or undefined
Returns a localized string if found in the culture, string not found otherwise
bitI18N.get('test'); // uses default browser culture
bitI18N.get('test', 'es');
bitI18N.get('test', 'es-MX');
Takes as arguments:
- a resources dictionaty
Throws an exception if:
- the value of any key is not a string, is null or undefined
bitI18N.setMany({
es: {
'Test': 'prueba'
},
en: {
'Test': 'test'
}
});
Takes as arguments:
- the culture of a localized resource
- the key of a localized resource
- the value of a localized resource
Throws an exception if:
- the argument culture is not a string, is null or undefined
- the argument key is not a string, is null or undefined
- the argument value is not a string, is null or undefined
bitI18N.set('es', 'test', 'Prueba');
bitI18N.set('en', 'test', 'Test');