feat: add runtime i18n with English, Vietnamese, and Simplified Chinese support
- Implement runtime i18n using MutationObserver for automatic DOM translation
- Add language switcher dropdown in dashboard header (EN/VI/ZH)
- Support 3 languages: English (default), Tiếng Việt, 简体中文
- Add translation files: vi.json (197 entries), zh-CN.json (513 entries, cleaned)
- Translate dashboard UI: sidebar menu, header, settings, MITM page
- Use cookie-based locale persistence with /api/locale endpoint
- Zero component changes required - translations applied at runtime
- Fix Header flicker on route change with key={pathname}
Co-authored-by: eachann <each1024@qq.com>
Based on PR #247 from decolua/9router with runtime approach
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
export const LOCALES = ["en", "vi", "zh-CN"];
|
||||
export const DEFAULT_LOCALE = "en";
|
||||
export const LOCALE_COOKIE = "locale";
|
||||
|
||||
export const LOCALE_NAMES = {
|
||||
"en": "English",
|
||||
"vi": "Tiếng Việt",
|
||||
"zh-CN": "简体中文"
|
||||
};
|
||||
|
||||
export function normalizeLocale(locale) {
|
||||
if (locale === "zh" || locale === "zh-CN") {
|
||||
return "zh-CN";
|
||||
}
|
||||
if (locale === "en") {
|
||||
return "en";
|
||||
}
|
||||
if (locale === "vi") {
|
||||
return "vi";
|
||||
}
|
||||
return DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
export function isSupportedLocale(locale) {
|
||||
return LOCALES.includes(locale);
|
||||
}
|
||||
Reference in New Issue
Block a user