mirror of
https://github.com/jech/galene.git
synced 2024-11-23 09:05:59 +01:00
ff50ff1195
Adapted from https://github.com/andreasremdt/simple-translator per Andreas Remdt <me@andreasremdt.com> (https://andreasremdt.com)
29 lines
785 B
JavaScript
29 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;
|
|
|