Micro i18n library for Javascript
Just download i18n.js and add it on your html page.
<!DOCTYPE HTML>
<html>
<head>
...
<script src="path/to/i18n.js" type="text/javascript"></script>
</head>
...
</html>Create your translation files in locales folder like this:
- /locales/en.json
- /locales/fr.json
- /locales/es.json
- /locales/de.json
In your main script :
window.addEventListener('load', function () {
int = new i18n();
int.translate();
});Fill your json with a structure like this :
{
"key": "translation"
}And, add the attribute data-i18n on elements you want to translate :
<span data-i18n="key"></span>- Chrome: 1
- Firefox: 3.5
- Internet Explorer: 9
- Opera: 10
- Safari: 3.2