Save selected app language on server

This commit is contained in:
schroda
2026-01-22 00:12:22 +01:00
parent 94ee49f3ca
commit bb36a46a24
9 changed files with 58 additions and 30 deletions

View File

@@ -7,6 +7,7 @@
*/
import { ISOLanguage, IsoLanguages } from '@/base/IsoLanguages.ts';
import { i18nResources } from '@/i18n';
export type LanguageObject = ISOLanguage & { orgCode: string; isoCode: string };
@@ -137,3 +138,12 @@ export function getLanguageReadingDirection(code: string): 'ltr' | 'rtl' {
return 'ltr';
}
export function detectLocale(): string {
const normalizedLanguageCodes = getPreferredISOLanguageCodes()
.filter((code) => code !== null)
.filter((code) => getISOLanguage(code))
.filter((code) => i18nResources.includes(code as (typeof i18nResources)[number]));
return normalizedLanguageCodes[0] ?? DEFAULT_LANGUAGE;
}