Files
ai-agent/web/i18n/config.ts
T
mlogclub f827a7471c refactor: remove LocaleSwitcher component and update locale handling
- Removed LocaleSwitcher from NavUser, SiteHeader, and WorkbenchHeader components.
- Updated tests to reflect the removal of LocaleSwitcher.
- Changed default locale from "en-US" to "zh-CN" in i18n configuration.
- Refactored locale resolution logic to read configured locale without relying on browser language detection.
- Updated AgentDesk SDK to support language configuration from public API.
- Cleaned up unused auth options fetching in the auth API.
2026-06-26 14:46:01 +08:00

49 lines
1.1 KiB
TypeScript

export const SUPPORTED_LOCALES = ["zh-CN", "en-US"] as const
export type AppLocale = (typeof SUPPORTED_LOCALES)[number]
export const DEFAULT_LOCALE: AppLocale = "zh-CN"
const LOCALE_ALIASES: Record<string, AppLocale> = {
zh: "zh-CN",
"zh-cn": "zh-CN",
zh_cn: "zh-CN",
"zh-hans": "zh-CN",
en: "en-US",
"en-us": "en-US",
en_us: "en-US",
}
export function normalizeLocale(value: string | null | undefined): AppLocale {
return normalizeSupportedLocale(value) ?? DEFAULT_LOCALE
}
function normalizeSupportedLocale(
value: string | null | undefined
): AppLocale | null {
if (!value) {
return null
}
const key = value.trim().toLowerCase()
return LOCALE_ALIASES[key] ?? null
}
export function isSupportedLocale(
value: string | null | undefined
): value is AppLocale {
if (!value) {
return false
}
return SUPPORTED_LOCALES.includes(value as AppLocale)
}
let configuredLocale: AppLocale = DEFAULT_LOCALE
export function readStoredLocale(): AppLocale {
return configuredLocale
}
export function configureLocale(locale: string | null | undefined): AppLocale {
configuredLocale = normalizeLocale(locale)
return configuredLocale
}