扩充多语言范围,新增7种多语言

This commit is contained in:
xintaofei
2026-03-09 15:31:34 +08:00
parent 32fbafa1fe
commit 08b33b5755
18 changed files with 9457 additions and 75 deletions

View File

@@ -1,11 +1,32 @@
import type { AppLocale, SystemLanguageSettings } from "@/lib/types"
export const APP_LOCALES: readonly AppLocale[] = ["en", "zh_cn", "zh_tw"]
export const APP_LOCALES: readonly AppLocale[] = [
"en",
"zh_cn",
"zh_tw",
"ja",
"ko",
"es",
"de",
"fr",
"pt",
"ar",
]
const FALLBACK_APP_LOCALE: AppLocale = "en"
export const LANGUAGE_SETTINGS_STORAGE_KEY = "codeg.system_language_settings"
export const LANGUAGE_MODE_COOKIE_KEY = "codeg.language_mode"
export const LANGUAGE_COOKIE_KEY = "codeg.locale"
export type IntlLocale = "en" | "zh-CN" | "zh-TW"
export type IntlLocale =
| "en"
| "zh-CN"
| "zh-TW"
| "ja"
| "ko"
| "es"
| "de"
| "fr"
| "pt"
| "ar"
export const DEFAULT_LANGUAGE_SETTINGS: SystemLanguageSettings = {
mode: "system",
@@ -16,12 +37,26 @@ export const APP_LOCALE_TO_INTL_LOCALE: Record<AppLocale, IntlLocale> = {
en: "en",
zh_cn: "zh-CN",
zh_tw: "zh-TW",
ja: "ja",
ko: "ko",
es: "es",
de: "de",
fr: "fr",
pt: "pt",
ar: "ar",
}
export const INTL_LOCALE_TO_APP_LOCALE: Record<IntlLocale, AppLocale> = {
en: "en",
"zh-CN": "zh_cn",
"zh-TW": "zh_tw",
ja: "ja",
ko: "ko",
es: "es",
de: "de",
fr: "fr",
pt: "pt",
ar: "ar",
}
export function isAppLocale(value: unknown): value is AppLocale {
@@ -29,7 +64,18 @@ export function isAppLocale(value: unknown): value is AppLocale {
}
export function isIntlLocale(value: unknown): value is IntlLocale {
return value === "en" || value === "zh-CN" || value === "zh-TW"
return (
value === "en" ||
value === "zh-CN" ||
value === "zh-TW" ||
value === "ja" ||
value === "ko" ||
value === "es" ||
value === "de" ||
value === "fr" ||
value === "pt" ||
value === "ar"
)
}
export function toIntlLocale(locale: AppLocale): IntlLocale {
@@ -70,6 +116,13 @@ export function mapLocaleTagToAppLocale(localeTag: string): AppLocale | null {
}
if (normalized.startsWith("zh")) return "zh_cn"
if (normalized.startsWith("ja")) return "ja"
if (normalized.startsWith("ko")) return "ko"
if (normalized.startsWith("es")) return "es"
if (normalized.startsWith("de")) return "de"
if (normalized.startsWith("fr")) return "fr"
if (normalized.startsWith("pt")) return "pt"
if (normalized.startsWith("ar")) return "ar"
return null
}

View File

@@ -554,7 +554,17 @@ export interface SystemProxySettings {
proxy_url: string | null
}
export type AppLocale = "en" | "zh_cn" | "zh_tw"
export type AppLocale =
| "en"
| "zh_cn"
| "zh_tw"
| "ja"
| "ko"
| "es"
| "de"
| "fr"
| "pt"
| "ar"
export type LanguageMode = "system" | "manual"
export interface SystemLanguageSettings {