feat: 优化C端语言切换和追溯码复制

This commit is contained in:
Nixevol
2026-06-30 20:22:53 +08:00
parent 5db963cb6f
commit be68e951f7
4 changed files with 147 additions and 23 deletions
+11 -2
View File
@@ -4,10 +4,19 @@ import enUS from './en-US.json';
const KEY = 'artveris_h5_locale';
// 支持的语言列表(后续新增语言只需在此追加)
export const SUPPORTED_LOCALES = [
{ value: 'zh-CN', label: '中文' },
{ value: 'en-US', label: 'English' },
];
export function getInitialLocale(): string {
const saved = localStorage.getItem(KEY);
if (saved) return saved;
return navigator.language.startsWith('en') ? 'en-US' : 'zh-CN';
if (saved && SUPPORTED_LOCALES.some((l) => l.value === saved)) return saved;
// 无保存值时自动跟随浏览器/系统语言
const sys = (navigator.languages?.[0] || navigator.language || '').toLowerCase();
const matched = SUPPORTED_LOCALES.find((l) => sys.startsWith(l.value.slice(0, 2)));
return matched?.value || 'zh-CN';
}
export const i18n = createI18n({