mirror of
https://github.com/jech/galene.git
synced 2024-11-14 20:55:57 +01:00
30 lines
785 B
JavaScript
30 lines
785 B
JavaScript
|
// The below provided options are default.
|
||
|
var translator = new Translator({
|
||
|
defaultLanguage: "en",
|
||
|
detectLanguage: true,
|
||
|
selector: "[data-i18n]",
|
||
|
debug: false,
|
||
|
registerGlobally: "__",
|
||
|
persist: false,
|
||
|
persistKey: "preferred_language",
|
||
|
filesLocation: "/lang"
|
||
|
});
|
||
|
|
||
|
translator.fetch(["en", "oc", "fr"]).then(() => {
|
||
|
// Calling `translatePageTo()` without any parameters
|
||
|
// will translate to the default language.
|
||
|
translator.translatePageTo();
|
||
|
registerLanguageToggle();
|
||
|
});
|
||
|
|
||
|
function registerLanguageToggle() {
|
||
|
var select = document.querySelector("select");
|
||
|
|
||
|
select.addEventListener("change", evt => {
|
||
|
var language = evt.target.value;
|
||
|
translator.translatePageTo(language);
|
||
|
});
|
||
|
};
|
||
|
document.getElementById(translator.currentLanguage).selected = true;
|
||
|
|