Add language support with english and german supported
This commit is contained in:
parent
d7033aec94
commit
173f104f58
4 changed files with 108 additions and 26 deletions
16
script.js
16
script.js
|
@ -72,3 +72,19 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
// Language support
|
||||
async function getLanguageData(lang){
|
||||
const response = await fetch(`languages/${lang}.json`);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const userLang = navigator.language || navigator.userLanguage;
|
||||
const langData = await getLanguageData(userLang);
|
||||
|
||||
document.querySelectorAll("[data-i18n]").forEach((element) => {
|
||||
const key = element.getAttribute("data-i18n");
|
||||
element.innerHTML = langData[key];
|
||||
});
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue