From 1ac1e74512b24e716dd0f77bef1ed8382ced8cd1 Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Wed, 8 Apr 2026 15:04:42 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20apply=20locale=20to=20DOM=20immediately?= =?UTF-8?q?=20on=20save=20=E2=80=94=20no=20reload=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- static/i18n.js | 13 +++++++++++++ static/index.html | 24 ++++++++++++------------ static/panels.js | 2 ++ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/static/i18n.js b/static/i18n.js index cd1f4ec..02318b8 100644 --- a/static/i18n.js +++ b/static/i18n.js @@ -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(); diff --git a/static/index.html b/static/index.html index 767157c..9452d0f 100644 --- a/static/index.html +++ b/static/index.html @@ -318,23 +318,23 @@