diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts index f85f17e8..f3e148ad 100644 --- a/frontend/src/i18n/index.ts +++ b/frontend/src/i18n/index.ts @@ -40,15 +40,26 @@ function detectInitialLang(): LangCode { return isSupported(nav) ? nav : "en"; } -const initial = detectInitialLang(); -void i18n.use(initReactI18next).init({ - resources, - lng: initial, - fallbackLng: "en", - interpolation: { escapeValue: false }, - returnNull: false, -}); -document.documentElement.lang = initial; +// Dev only: a locale edit re-runs THIS module (it accepts its own update, below) instead of climbing to +// main.tsx — a re-run main.tsx called createRoot on the live container a second time, and the two roots +// tore each other's DOM down ("removeChild … not a child" by the dozen, each one a fatal toast that evicted +// an old notification). On a re-run the i18next singleton is already up: swap the texts in and re-render. +if (i18n.isInitialized) { + for (const [lng, r] of Object.entries(resources)) + i18n.addResourceBundle(lng, "translation", r.translation, true, true); + void i18n.changeLanguage(i18n.language); +} else { + const initial = detectInitialLang(); + void i18n.use(initReactI18next).init({ + resources, + lng: initial, + fallbackLng: "en", + interpolation: { escapeValue: false }, + returnNull: false, + }); + document.documentElement.lang = initial; +} +if (import.meta.hot) import.meta.hot.accept(); export function setLanguage(code: LangCode): void { void i18n.changeLanguage(code);