Add language support with english and german supported

This commit is contained in:
Patrick Schwarzer 2025-05-12 22:22:12 +02:00
parent d7033aec94
commit 173f104f58
4 changed files with 108 additions and 26 deletions

View file

@ -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];
});
})