diff --git a/src/lib/i18n/index.ts b/src/lib/i18n/index.ts index d7361a5e79..520f9337a2 100644 --- a/src/lib/i18n/index.ts +++ b/src/lib/i18n/index.ts @@ -14,8 +14,11 @@ const createI18nStore = (i18n: i18nType) => { i18nWritable.set(i18n); }); i18n.on('added', () => i18nWritable.set(i18n)); - i18n.on('languageChanged', () => { + i18n.on('languageChanged', (lang) => { i18nWritable.set(i18n); + if (typeof document !== 'undefined') { + document.documentElement.setAttribute('lang', lang); + } }); return i18nWritable; }; @@ -67,9 +70,6 @@ export const initI18n = (defaultLocale?: string | undefined) => { escapeValue: false // not needed for svelte as it escapes by default } }); - - const lang = i18next?.language || defaultLocale || 'en-US'; - document.documentElement.setAttribute('lang', lang); }; const i18n = createI18nStore(i18next);