Created
February 3, 2021 09:55
-
-
Save honzabilek4/d816177d14324ad8b3e63dc73a34bfa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { i18n, initI18n, getLanguages, getCurrentLanguage } from "./i18n"; | |
const createLanguageSelector = () => { | |
let template = '<select id="selector">'; | |
getLanguages().forEach((l) => { | |
template += ` | |
<option ${l.language === getCurrentLanguage() ? "selected" : ""} value="${ | |
l.language | |
}"> | |
${l.localizedName} | |
</option>`; | |
}); | |
template += "</select>"; | |
return template; | |
}; | |
const getTranslatedContent = () => { | |
return i18n.t("hello_localazy"); | |
}; | |
const updateTranslatedContent = () => { | |
document.querySelector("#content").innerHTML = getTranslatedContent(); | |
}; | |
const initPageContent = () => { | |
document.querySelector("#app").innerHTML = ` | |
${createLanguageSelector()} | |
<div id="content"> | |
${getTranslatedContent()} | |
</div>`; | |
document.querySelector("#selector").addEventListener("change", (e) => { | |
i18n.changeLanguage(e.target.value); | |
updateTranslatedContent(); | |
}); | |
}; | |
initI18n(initPageContent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment