fix(app): clean up i18n settings labels
This commit is contained in:
@@ -19,6 +19,64 @@ export const LANGUAGE_OPTIONS: LanguageOption[] = [
|
||||
];
|
||||
|
||||
const SUPPORTED_LANGUAGES = new Set<AppLanguage>(["system", "ar", "en", "es", "fr", "ru", "zh-CN"]);
|
||||
const LANGUAGE_NATIVE_NAMES: Record<SupportedLocale, string> = {
|
||||
ar: "العربية",
|
||||
en: "English",
|
||||
es: "Español",
|
||||
fr: "Français",
|
||||
ru: "Русский",
|
||||
"zh-CN": "简体中文",
|
||||
};
|
||||
const LANGUAGE_NAMES_BY_LOCALE: Record<SupportedLocale, Record<SupportedLocale, string>> = {
|
||||
ar: {
|
||||
ar: "العربية",
|
||||
en: "الإنجليزية",
|
||||
es: "الإسبانية",
|
||||
fr: "الفرنسية",
|
||||
ru: "الروسية",
|
||||
"zh-CN": "الصينية المبسطة",
|
||||
},
|
||||
en: {
|
||||
ar: "Arabic",
|
||||
en: "English",
|
||||
es: "Spanish",
|
||||
fr: "French",
|
||||
ru: "Russian",
|
||||
"zh-CN": "Simplified Chinese",
|
||||
},
|
||||
es: {
|
||||
ar: "árabe",
|
||||
en: "inglés",
|
||||
es: "español",
|
||||
fr: "francés",
|
||||
ru: "ruso",
|
||||
"zh-CN": "chino simplificado",
|
||||
},
|
||||
fr: {
|
||||
ar: "arabe",
|
||||
en: "anglais",
|
||||
es: "espagnol",
|
||||
fr: "français",
|
||||
ru: "russe",
|
||||
"zh-CN": "chinois simplifié",
|
||||
},
|
||||
ru: {
|
||||
ar: "арабский",
|
||||
en: "английский",
|
||||
es: "испанский",
|
||||
fr: "французский",
|
||||
ru: "русский",
|
||||
"zh-CN": "упрощенный китайский",
|
||||
},
|
||||
"zh-CN": {
|
||||
ar: "阿拉伯语",
|
||||
en: "英语",
|
||||
es: "西班牙语",
|
||||
fr: "法语",
|
||||
ru: "俄语",
|
||||
"zh-CN": "简体中文",
|
||||
},
|
||||
};
|
||||
|
||||
export function parseAppLanguage(value: unknown): AppLanguage | null {
|
||||
return typeof value === "string" && SUPPORTED_LANGUAGES.has(value as AppLanguage)
|
||||
@@ -26,6 +84,24 @@ export function parseAppLanguage(value: unknown): AppLanguage | null {
|
||||
: null;
|
||||
}
|
||||
|
||||
export function formatLanguageOptionLabel(
|
||||
option: LanguageOption,
|
||||
activeLocale: SupportedLocale,
|
||||
systemLabel: string,
|
||||
): string {
|
||||
if (option.value === "system") {
|
||||
return systemLabel;
|
||||
}
|
||||
|
||||
const nativeName = LANGUAGE_NATIVE_NAMES[option.value];
|
||||
const activeLanguageName = LANGUAGE_NAMES_BY_LOCALE[activeLocale][option.value];
|
||||
if (nativeName === activeLanguageName) {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
return `${nativeName} - ${activeLanguageName}`;
|
||||
}
|
||||
|
||||
export function resolveSupportedLocale(
|
||||
language: AppLanguage,
|
||||
systemLocales: readonly string[],
|
||||
@@ -39,6 +115,9 @@ export function resolveSupportedLocale(
|
||||
if (normalized === "ar" || normalized.startsWith("ar-")) {
|
||||
return "ar";
|
||||
}
|
||||
if (normalized === "en" || normalized.startsWith("en-")) {
|
||||
return "en";
|
||||
}
|
||||
if (normalized === "es" || normalized.startsWith("es-")) {
|
||||
return "es";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user