fix: default app language to English
Stop auto-detecting locale from system/browser on first launch Use saved language preference when users explicitly choose one
This commit is contained in:
@@ -78,35 +78,11 @@ export function writeStoredLocale(locale: Locale): void {
|
||||
}
|
||||
}
|
||||
|
||||
function getRuntimeLanguage(): string | undefined {
|
||||
if (typeof window === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return (window as unknown as { __OPENCHAMBER_RUNTIME_APIS__?: { runtime?: { language?: string } } })
|
||||
.__OPENCHAMBER_RUNTIME_APIS__?.runtime?.language;
|
||||
}
|
||||
|
||||
export function detectInitialLocale(): Locale {
|
||||
const stored = readStoredLocale();
|
||||
if (stored) {
|
||||
return stored;
|
||||
}
|
||||
|
||||
const runtimeLanguage = getRuntimeLanguage();
|
||||
if (runtimeLanguage) {
|
||||
return normalizeLocale(runtimeLanguage);
|
||||
}
|
||||
|
||||
if (typeof navigator !== 'undefined') {
|
||||
const languages = navigator.languages?.length ? navigator.languages : [navigator.language];
|
||||
for (const language of languages) {
|
||||
const locale = normalizeLocale(language);
|
||||
if (locale !== DEFAULT_LOCALE) {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user