Files
monkey-ai-web/src/i18n/catalog.js
T
2026-10-15 16:33:46 +08:00

84 lines
2.8 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.
/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// 界面语言目录——前端唯一来源(加载器、顶栏展示、后台配置页均从这里取)。
//
// 新增语种:补 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;
};