RPG Companion Settings Pop-up window [done]

This commit is contained in:
Mingyu
2025-11-24 17:37:38 +08:00
committed by GitHub
parent 8ef4e4ba6d
commit 0f0a4dceeb
4 changed files with 198 additions and 62 deletions
+24 -2
View File
@@ -41,14 +41,36 @@ class Internationalization {
if (!rootElement) {
return;
}
const elements = rootElement.querySelectorAll('[data-i18n-key]');
elements.forEach(element => {
// 1. Translate textContent
const textElements = rootElement.querySelectorAll('[data-i18n-key]');
textElements.forEach(element => {
const key = element.dataset.i18nKey;
const translation = this.getTranslation(key);
if (translation) {
element.textContent = translation;
}
});
// 2. Translate title attribute
const titleElements = rootElement.querySelectorAll('[data-i18n-title]');
titleElements.forEach(element => {
const key = element.dataset.i18nTitle;
const translation = this.getTranslation(key);
if (translation) {
element.setAttribute('title', translation);
}
});
// 3. Translate aria-label attribute
const ariaLabelElements = rootElement.querySelectorAll('[data-i18n-aria-label]');
ariaLabelElements.forEach(element => {
const key = element.dataset.i18nAriaLabel;
const translation = this.getTranslation(key);
if (translation) {
element.setAttribute('aria-label', translation);
}
});
}
getTranslation(key) {