Files
monkey-ai-web/src/i18n/catalog.js
T
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

65 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 界面语言目录——前端唯一来源(加载器、顶栏展示、后台配置页均从这里取)。
//
// 新增语种:补 locales/xx.json → 在此登记 → 后端 setting/language_setting 的
// SupportedLanguages 同步(Go 契约测试会比对两边语言码)。
//
// 保持纯数据:不引 React、不静态 import JSON,bootstrap 的 node 单测直接加载本文件。
// endonym 一律用该语言自称,用户看不懂当前界面语言时仍能认出自己的那一项;
// flag 为国家码,由展示层映射到旗帜组件(简繁共用 CN,靠自称区分)。
export const LANGUAGE_CATALOG = [
// zh 由 i18n.js 同步打包,无需按需加载
{ code: 'zh', endonym: '简体中文', flag: 'CN', load: null },
{
code: 'zh-TW',
endonym: '繁體中文',
flag: 'CN',
load: () => import('./locales/zh-TW.json'),
},
{
code: 'en',
endonym: 'English',
flag: 'GB',
load: () => import('./locales/en.json'),
},
{
code: 'ja',
endonym: '日本語',
flag: 'JP',
load: () => import('./locales/ja.json'),
},
{
code: 'ko',
endonym: '한국어',
flag: 'KR',
load: () => import('./locales/ko.json'),
},
{
code: 'vi',
endonym: 'Tiếng Việt',
flag: 'VN',
load: () => import('./locales/vi.json'),
},
{
code: 'th',
endonym: 'ไทย',
flag: 'TH',
load: () => import('./locales/th.json'),
},
];
export const LANGUAGE_CODES = LANGUAGE_CATALOG.map((entry) => entry.code);
export const isSupportedLanguage = (code) => LANGUAGE_CODES.includes(code);
export const getLanguageEntry = (code) =>
LANGUAGE_CATALOG.find((entry) => entry.code === code) || null;
// 按后台配置的启用语言过滤并排序;配置缺失时展示全部
export const orderEnabledLanguages = (enabledLanguages) => {
if (!Array.isArray(enabledLanguages) || enabledLanguages.length === 0) {
return LANGUAGE_CATALOG;
}
const entries = enabledLanguages.map(getLanguageEntry).filter(Boolean);
return entries.length > 0 ? entries : LANGUAGE_CATALOG;
};