🐛 修復音效通知區域語系初始化問題

This commit is contained in:
Minidoracat 2025-06-14 10:40:36 +08:00
parent 3d4aafa3dc
commit 663b806d59
2 changed files with 49 additions and 4 deletions

View File

@ -321,10 +321,10 @@ class I18nManager {
}
updateAudioSelectTranslations() {
// 更新音效選擇器的翻譯
// 更新音效設定區域的所有翻譯
if (window.feedbackApp && window.feedbackApp.audioSettingsUI) {
if (typeof window.feedbackApp.audioSettingsUI.updateAudioSelectTranslations === 'function') {
window.feedbackApp.audioSettingsUI.updateAudioSelectTranslations();
if (typeof window.feedbackApp.audioSettingsUI.updateTranslations === 'function') {
window.feedbackApp.audioSettingsUI.updateTranslations();
}
}
}

View File

@ -58,7 +58,10 @@
this.createUI();
this.setupEventListeners();
this.refreshUI();
// 主動應用翻譯到新創建的元素
this.applyInitialTranslations();
console.log('✅ AudioSettingsUI 初始化完成');
};
@ -637,6 +640,48 @@
/**
* 應用初始翻譯到新創建的元素
*/
AudioSettingsUI.prototype.applyInitialTranslations = function() {
if (!this.container) return;
// 對容器內所有有 data-i18n 屬性的元素應用翻譯
const elements = this.container.querySelectorAll('[data-i18n]');
elements.forEach(element => {
const key = element.getAttribute('data-i18n');
const translation = this.t(key);
if (translation && translation !== key) {
element.textContent = translation;
}
});
// 對有 data-i18n-placeholder 屬性的元素應用翻譯
const placeholderElements = this.container.querySelectorAll('[data-i18n-placeholder]');
placeholderElements.forEach(element => {
const key = element.getAttribute('data-i18n-placeholder');
const translation = this.t(key);
if (translation && translation !== key) {
element.placeholder = translation;
}
});
console.log('🌐 AudioSettingsUI 初始翻譯已應用');
};
/**
* 更新所有翻譯包括靜態文字和動態內容
*/
AudioSettingsUI.prototype.updateTranslations = function() {
// 更新所有靜態文字元素
this.applyInitialTranslations();
// 更新音效選擇器的翻譯
this.updateAudioSelectTranslations();
console.log('🌐 AudioSettingsUI 翻譯已更新');
};
/**
* 更新音效選擇器的翻譯
*/