translato
v1.0.0
Published
Translato is a javascript library that helps to translate a html page into different languages with a previous defined JSON dictionary.
Downloads
10
Maintainers
Readme
Translato
Translato is a javascript library that helps to translate a html page into different languages with a previous defined JSON dictionary.
Installation
Install via NodeJS and NPM:
npm install translato --save
Usage
Example
<body>
<h1 data-tl="start.headline"></h1>
<div id="container"></div>
<script src="translato.js"></script>
<script>
translato.setDictionary({
start: {
headline: {
en: "Hello World",
de: "Hallo Welt"
},
content: {
en: "Here is awesome content.",
de: "Hier ist unglaublicher Inhalt."
}
}
});
translato.setLocale("en");
let element = document.getElementById("container");
element.innerHTML = translato.translateKeys("content");
</script>
</body>
API
translato.on({string} eventName, {function} callback)
- listen for events in translatotranslato.translateKeys({strings} keys...)
- translate keys, returns an array if multiple keys are giventranslato.translatePage()
- translate the whole pagetranslato.translateHTML({string} html)
- translate the given HTML stringtranslato.setLocale({string} languageKey, {boolean} translatePage?)
- language identifier, depends on dictionarytranslato.setDictionary({object} dictionary)
- set the whole dictionary for the translations
Events
translato.on("languageChanged", function)
- is fired when setLocale is executed