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.
This commit is contained in:
mlogclub
2026-06-26 14:46:01 +08:00
parent 12d188fc7e
commit f827a7471c
32 changed files with 215 additions and 268 deletions
+6 -34
View File
@@ -1,8 +1,7 @@
export const SUPPORTED_LOCALES = ["zh-CN", "en-US"] as const
export type AppLocale = (typeof SUPPORTED_LOCALES)[number]
export const DEFAULT_LOCALE: AppLocale = "en-US"
export const LOCALE_STORAGE_KEY = "cs_ai_agent_locale"
export const DEFAULT_LOCALE: AppLocale = "zh-CN"
const LOCALE_ALIASES: Record<string, AppLocale> = {
zh: "zh-CN",
@@ -37,40 +36,13 @@ export function isSupportedLocale(
return SUPPORTED_LOCALES.includes(value as AppLocale)
}
export function resolveBrowserLocale({
storedLocale,
navigatorLanguages,
}: {
storedLocale?: string | null
navigatorLanguages?: readonly string[] | null
}): AppLocale {
if (isSupportedLocale(storedLocale)) {
return storedLocale
}
for (const locale of navigatorLanguages ?? []) {
const normalized = normalizeSupportedLocale(locale)
if (normalized) {
return normalized
}
}
return DEFAULT_LOCALE
}
let configuredLocale: AppLocale = DEFAULT_LOCALE
export function readStoredLocale(): AppLocale {
if (typeof window === "undefined") {
return DEFAULT_LOCALE
}
return resolveBrowserLocale({
storedLocale: window.localStorage.getItem(LOCALE_STORAGE_KEY),
navigatorLanguages: window.navigator.languages,
})
return configuredLocale
}
export function writeStoredLocale(locale: AppLocale) {
if (typeof window === "undefined") {
return
}
window.localStorage.setItem(LOCALE_STORAGE_KEY, locale)
export function configureLocale(locale: string | null | undefined): AppLocale {
configuredLocale = normalizeLocale(locale)
return configuredLocale
}