Save selected app language on server
This commit is contained in:
@@ -7,8 +7,7 @@
|
||||
*/
|
||||
|
||||
import { i18n } from '@lingui/core';
|
||||
import { DEFAULT_LANGUAGE, getISOLanguage, getPreferredISOLanguageCodes } from '@/lib/ISOLanguageUtil.ts';
|
||||
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
||||
import { detectLocale } from '@/lib/ISOLanguageUtil.ts';
|
||||
import localesConfig from '@/i18n/locales.json';
|
||||
|
||||
export const i18nResources = localesConfig.locales;
|
||||
@@ -17,28 +16,11 @@ export type I18nResourceCode = (typeof i18nResources)[number];
|
||||
|
||||
const DEFAULT_LOCALE = localesConfig.defaultLocale;
|
||||
|
||||
const SELECTED_LANGUAGE_CODE_KEY = 'i18n:selected-language';
|
||||
|
||||
export async function loadCatalog(locale: string): Promise<void> {
|
||||
const localeToLoad = i18nResources.includes(locale as (typeof i18nResources)[number]) ? locale : DEFAULT_LOCALE;
|
||||
|
||||
const { messages } = await import(`./locales/${localeToLoad}.po`);
|
||||
i18n.loadAndActivate({ locale: localeToLoad, messages });
|
||||
|
||||
AppStorage.local.setItem(SELECTED_LANGUAGE_CODE_KEY, localeToLoad);
|
||||
}
|
||||
|
||||
function detectLocale(): string {
|
||||
const storedLanguage = AppStorage.local.getItem(SELECTED_LANGUAGE_CODE_KEY);
|
||||
const preferredLanguages = getPreferredISOLanguageCodes();
|
||||
const languageCodes = [storedLanguage, ...preferredLanguages];
|
||||
|
||||
const normalizedLanguageCodes = languageCodes
|
||||
.filter((code) => code !== null)
|
||||
.filter((code) => getISOLanguage(code))
|
||||
.filter((code) => i18nResources.includes(code as (typeof i18nResources)[number]));
|
||||
|
||||
return normalizedLanguageCodes[0] ?? DEFAULT_LANGUAGE;
|
||||
}
|
||||
|
||||
export async function initializeLocalization(): Promise<void> {
|
||||
|
||||
@@ -985,6 +985,10 @@ msgstr "Could not restore backup"
|
||||
msgid "Could not retry failed download."
|
||||
msgstr "Could not retry failed download."
|
||||
|
||||
#: src/features/settings/screens/Appearance.tsx
|
||||
msgid "Could not save changes"
|
||||
msgstr "Could not save changes"
|
||||
|
||||
#: src/features/category/components/CategorySelect.tsx
|
||||
#: src/features/library/components/LibraryOptionsPanel.tsx
|
||||
#: src/features/library/screens/LibrarySettings.tsx
|
||||
|
||||
Reference in New Issue
Block a user