feat: add alt text to images
This commit is contained in:
11
src/index.js
11
src/index.js
@@ -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));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user