mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
fix(app): only remember a language the user picked (#3398)
This commit is contained in:
1 parent
d7aa6ec2aa
commit
5b3f69bf27
2 files changed
+6
-4
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import {messages as messagesEnUS} from '@app/features/i18n/locales/en-US/messages.mjs';
|
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 AppStorage from '@app/features/platform/state/PersistentStorage';
|
||||||
import {getNativeLocaleIdentifier} from '@app/features/platform/types/Platform';
|
import {getNativeLocaleIdentifier} from '@app/features/platform/types/Platform';
|
||||||
import {Logger} from '@app/features/platform/utils/AppLogger';
|
import {Logger} from '@app/features/platform/utils/AppLogger';
|
||||||
@@ -145,7 +146,7 @@ function detectPreferredLocale(forceLocale?: string): LocaleCode {
|
|||||||
if (forceLocale) {
|
if (forceLocale) {
|
||||||
return normalizeLocale(forceLocale);
|
return normalizeLocale(forceLocale);
|
||||||
}
|
}
|
||||||
const storedLocale = AppStorage.getItem('locale');
|
const storedLocale = AppStorage.getItem(AppStorageKey.I18N_CHOSEN_LOCALE);
|
||||||
if (storedLocale) {
|
if (storedLocale) {
|
||||||
return normalizeLocale(storedLocale);
|
return normalizeLocale(storedLocale);
|
||||||
}
|
}
|
||||||
@@ -166,7 +167,6 @@ function activateLocale(localeCode: LocaleCode, messages: Messages): void {
|
|||||||
document.documentElement.lang = localeCode;
|
document.documentElement.lang = localeCode;
|
||||||
}
|
}
|
||||||
noteLocale(localeCode);
|
noteLocale(localeCode);
|
||||||
AppStorage.setItem('locale', localeCode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensureActiveLocale(): void {
|
export function ensureActiveLocale(): void {
|
||||||
@@ -208,10 +208,10 @@ export function applyLocaleChange(localeCode: string): LocaleCode {
|
|||||||
const normalized = normalizeLocale(localeCode);
|
const normalized = normalizeLocale(localeCode);
|
||||||
requestedLocale = normalized;
|
requestedLocale = normalized;
|
||||||
if (normalized === i18n.locale) {
|
if (normalized === i18n.locale) {
|
||||||
AppStorage.setItem('locale', normalized);
|
AppStorage.setItem(AppStorageKey.I18N_CHOSEN_LOCALE, normalized);
|
||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
AppStorage.setItem('locale', normalized);
|
AppStorage.setItem(AppStorageKey.I18N_CHOSEN_LOCALE, normalized);
|
||||||
void loadLocaleCatalog(normalized).catch((error) => {
|
void loadLocaleCatalog(normalized).catch((error) => {
|
||||||
logger.error(`Failed to apply locale ${normalized}`, error);
|
logger.error(`Failed to apply locale ${normalized}`, error);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ export const AppStorageKey = Object.freeze({
|
|||||||
AUTH_SESSION_USER_ID: AuthSessionStorageKey.UserId,
|
AUTH_SESSION_USER_ID: AuthSessionStorageKey.UserId,
|
||||||
BACKGROUND_ACCOUNT_PRESENCE: 'BackgroundAccountPresence',
|
BACKGROUND_ACCOUNT_PRESENCE: 'BackgroundAccountPresence',
|
||||||
DELETED_KEYS: 'fluxer:internal:deleted-keys',
|
DELETED_KEYS: 'fluxer:internal:deleted-keys',
|
||||||
|
I18N_CHOSEN_LOCALE: 'fluxer:i18n:chosen-locale',
|
||||||
MESSAGING_DRAFTS: 'Drafts',
|
MESSAGING_DRAFTS: 'Drafts',
|
||||||
MESSAGING_MESSAGE_EDIT: 'MessageEdit',
|
MESSAGING_MESSAGE_EDIT: 'MessageEdit',
|
||||||
NOTIFICATION: 'Notification',
|
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_TOKEN]: true,
|
||||||
[AppStorageKey.AUTH_SESSION_USER_ID]: true,
|
[AppStorageKey.AUTH_SESSION_USER_ID]: true,
|
||||||
[AppStorageKey.BACKGROUND_ACCOUNT_PRESENCE]: true,
|
[AppStorageKey.BACKGROUND_ACCOUNT_PRESENCE]: true,
|
||||||
|
[AppStorageKey.I18N_CHOSEN_LOCALE]: true,
|
||||||
[AppStorageKey.THEME_LIBRARY_ENABLED_IDS]: true,
|
[AppStorageKey.THEME_LIBRARY_ENABLED_IDS]: true,
|
||||||
[AppStorageKey.THEME_LIBRARY_LOCAL_FILES]: true,
|
[AppStorageKey.THEME_LIBRARY_LOCAL_FILES]: true,
|
||||||
[AppStorageKey.THEME_LIBRARY_MIGRATED]: true,
|
[AppStorageKey.THEME_LIBRARY_MIGRATED]: true,
|
||||||
|
|||||||
Reference in new issue
Block a user