Prevent language switch on initial load

The change of bb36a46a24 causes a "language blink" on the initial load.
This happens due to having to wait till the selected language has been loaded from the server. Until this request is resolved, lingui initializes with the detected language, which might not match the selected one. This then causes the language to potentially be changed shortly after the initial load to a different language.
This commit is contained in:
schroda
2026-01-23 02:15:26 +01:00
parent bb36a46a24
commit 12cac252de
2 changed files with 12 additions and 2 deletions

View File

@@ -7,8 +7,9 @@
*/
import { i18n } from '@lingui/core';
import { detectLocale } from '@/lib/ISOLanguageUtil.ts';
import { detectLocale, SELECTED_LANGUAGE_CODE_KEY } from '@/lib/ISOLanguageUtil.ts';
import localesConfig from '@/i18n/locales.json';
import { AppStorage } from '@/lib/storage/AppStorage.ts';
export const i18nResources = localesConfig.locales;
@@ -21,6 +22,8 @@ export async function loadCatalog(locale: string): Promise<void> {
const { messages } = await import(`./locales/${localeToLoad}.po`);
i18n.loadAndActivate({ locale: localeToLoad, messages });
AppStorage.local.setItem(SELECTED_LANGUAGE_CODE_KEY, localeToLoad);
}
export async function initializeLocalization(): Promise<void> {