fix: apply locale to DOM immediately on save — no reload needed
Add applyLocaleToDOM() which walks [data-i18n] elements and re-stamps their textContent from t(). Called after setLocale() in saveSettings() so the settings panel labels, checkboxes, and save button update live. Also called on boot after /api/settings resolves so Chinese persists without flicker on reload. - static/i18n.js: add applyLocaleToDOM() function - static/index.html: add data-i18n attributes to all settings panel static text nodes (labels, checkbox spans, save button) - static/panels.js: call applyLocaleToDOM() + syncTopbar() after save - static/boot.js: call applyLocaleToDOM() alongside setLocale() on boot
This commit is contained in:
@@ -285,5 +285,18 @@ function loadLocale() {
|
||||
setLocale(saved);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-stamp all [data-i18n] elements in the DOM with the current locale.
|
||||
* Safe to call at any time — missing keys fall back to English.
|
||||
* Call after setLocale() to make static HTML text update without a reload.
|
||||
*/
|
||||
function applyLocaleToDOM() {
|
||||
document.querySelectorAll('[data-i18n]').forEach(el => {
|
||||
const key = el.getAttribute('data-i18n');
|
||||
const val = t(key);
|
||||
if (val && val !== key) el.textContent = val;
|
||||
});
|
||||
}
|
||||
|
||||
// Apply saved locale immediately so there's no flash of English on reload.
|
||||
loadLocale();
|
||||
|
||||
Reference in New Issue
Block a user