feat: add alt text to images

This commit is contained in:
2024-07-31 19:17:01 +02:00
parent ac2715f5f4
commit e2632c3934
4 changed files with 25 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ async function initI18next() {
}
function translatePageElements() {
// Translate content inside a tag
const translatableElements = document.querySelectorAll(
"[data-i18n-key]",
);
@@ -32,6 +33,16 @@ function translatePageElements() {
const key = el.getAttribute("data-i18n-key");
el.innerHTML = i18next.t(key);
});
// Translate alt texts
const translatableAltTexts = document.querySelectorAll(
"[alt]",
);
translatableAltTexts.forEach((el) => {
const translation_key = el.getAttribute("alt");
console.log(el);
el.setAttribute("alt", i18next.t(translation_key));
console.log(i18next.t(translation_key));
});
}