Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): only remember a language the user picked (#3398)

Hampus5b3f69bf2736
diff --git a/fluxer_app/src/app/I18n.ts b/fluxer_app/src/app/I18n.ts
index a08d19282..5590b892a 100644
--- a/fluxer_app/src/app/I18n.ts
+++ b/fluxer_app/src/app/I18n.ts
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {messages as messagesEnUS} from '@app/features/i18n/locales/en-US/messages.mjs';
+import {AppStorageKey} from '@app/features/platform/state/AppStorageKeys';
import AppStorage from '@app/features/platform/state/PersistentStorage';
import {getNativeLocaleIdentifier} from '@app/features/platform/types/Platform';
import {Logger} from '@app/features/platform/utils/AppLogger';
@@ -145,7 +146,7 @@ function detectPreferredLocale(forceLocale?: string): LocaleCode {
if (forceLocale) {
return normalizeLocale(forceLocale);
}
- const storedLocale = AppStorage.getItem('locale');
+ const storedLocale = AppStorage.getItem(AppStorageKey.I18N_CHOSEN_LOCALE);
if (storedLocale) {
return normalizeLocale(storedLocale);
}
@@ -166,7 +167,6 @@ function activateLocale(localeCode: LocaleCode, messages: Messages): void {
document.documentElement.lang = localeCode;
}
noteLocale(localeCode);
- AppStorage.setItem('locale', localeCode);
}
export function ensureActiveLocale(): void {
@@ -208,10 +208,10 @@ export function applyLocaleChange(localeCode: string): LocaleCode {
const normalized = normalizeLocale(localeCode);
requestedLocale = normalized;
if (normalized === i18n.locale) {
- AppStorage.setItem('locale', normalized);
+ AppStorage.setItem(AppStorageKey.I18N_CHOSEN_LOCALE, normalized);
return normalized;
}
- AppStorage.setItem('locale', normalized);
+ AppStorage.setItem(AppStorageKey.I18N_CHOSEN_LOCALE, normalized);
void loadLocaleCatalog(normalized).catch((error) => {
logger.error(`Failed to apply locale ${normalized}`, error);
});
diff --git a/fluxer_app/src/features/platform/state/AppStorageKeys.ts b/fluxer_app/src/features/platform/state/AppStorageKeys.ts
index 03b6d413b..7769a5ddb 100644
--- a/fluxer_app/src/features/platform/state/AppStorageKeys.ts
+++ b/fluxer_app/src/features/platform/state/AppStorageKeys.ts
@@ -14,6 +14,7 @@ export const AppStorageKey = Object.freeze({
AUTH_SESSION_USER_ID: AuthSessionStorageKey.UserId,
BACKGROUND_ACCOUNT_PRESENCE: 'BackgroundAccountPresence',
DELETED_KEYS: 'fluxer:internal:deleted-keys',
+ I18N_CHOSEN_LOCALE: 'fluxer:i18n:chosen-locale',
MESSAGING_DRAFTS: 'Drafts',
MESSAGING_MESSAGE_EDIT: 'MessageEdit',
NOTIFICATION: 'Notification',
@@ -51,6 +52,7 @@ const GLOBAL_APP_STORAGE_KEY_LOOKUP: Readonly<Record<string, true>> = Object.fre
[AppStorageKey.AUTH_SESSION_TOKEN]: true,
[AppStorageKey.AUTH_SESSION_USER_ID]: true,
[AppStorageKey.BACKGROUND_ACCOUNT_PRESENCE]: true,
+ [AppStorageKey.I18N_CHOSEN_LOCALE]: true,
[AppStorageKey.THEME_LIBRARY_ENABLED_IDS]: true,
[AppStorageKey.THEME_LIBRARY_LOCAL_FILES]: true,
[AppStorageKey.THEME_LIBRARY_MIGRATED]: true,