/** * Locale configuration for the dashboard's lightweight i18n layer. * * The implementation intentionally mirrors the existing `next-themes` / * `use-sidebar-collapsed` patterns already used in this codebase: a small * client Context backed by localStorage, no extra dependency, SSR-safe via * `useSyncExternalStore`. */ /** Supported UI languages. `zh` is the source-of-truth for copy. */ export type Locale = "zh" | "en"; /** All selectable locales, in display order (used by the toggle control). */ export const LOCALES: readonly Locale[] = ["zh", "en"] as const; /** Fallback when nothing is stored yet — matches the current ``. */ export const DEFAULT_LOCALE: Locale = "zh"; /** localStorage key holding the persisted locale preference. */ export const LOCALE_STORAGE_KEY = "dashboard.locale"; /** Custom window event used to sync locale across mounted hook instances. */ export const LOCALE_EVENT_NAME = "dashboard-locale-change"; /** Short label shown inside the language toggle for each locale. */ export const LOCALE_LABELS: Record = { zh: "中", en: "EN", }; /** Full name used for tooltips / aria-labels. */ export const LOCALE_NAMES: Record = { zh: "中文", en: "English", }; /** The `lang` attribute value for `` per locale. */ export const LOCALE_HTML_LANG: Record = { zh: "zh-CN", en: "en", }; /** Narrow an arbitrary string to a valid Locale, falling back to default. */ export function normalizeLocale(value: string | null | undefined): Locale { return value === "en" || value === "zh" ? value : DEFAULT_LOCALE; }