feat(i18n): 将前端用户可见中文硬编码改为四语言

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
sophieandCursor committed 2026-07-30 14:39:16 +08:00
1 parent dce915ea30
commit ac7b53a523
105 files changed
+2928 -647

No files matched your search

@@ -1,9 +1,10 @@
/**
* features/chat/training/trainingChatQuestions.ts
* 用途:统一维护员工培训 Agent 的员工版 / HR 版聊天常见问题默认值与解析逻辑。
* 依赖:被 Admin 后台培训配置表单与 Chat 欢迎区共同引用,避免默认问题与字段名出现多份散落副本。
* 逻辑:优先读取 extra_config.training_config 中的角色化问题列表;未配置时回退到内置示例,显式保存空数组时尊重为空。
* 依赖:vue-i18n(默认问题从 chat.training.defaultQuestions.* 读取)、Admin 培训配置表单与 Chat 欢迎区。
* 逻辑:优先读取 extra_config.training_config 中的角色化问题列表;未配置时回退到 i18n 内置示例,显式保存空数组时尊重为空。
*/
import i18n from '@/i18n';
export type TrainingChatQuestionRole = 'employee' | 'hr';
@@ -12,19 +13,25 @@ const TRAINING_ROLE_QUESTION_KEYS: Record<TrainingChatQuestionRole, string[]> =
hr: ['hr_chat_suggested_questions', 'admin_chat_suggested_questions'],
};
export const DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS = [
'这次员工培训主要学习什么内容?',
'完成培训需要经过哪些步骤?',
'员工培训的通过规则是什么?',
'开始考试前需要注意什么?',
];
/**
* 读取当前语言下的培训默认常见问题列表。
* 核心逻辑:从 chat.training.defaultQuestions.{role} 取数组;非数组时回退空列表。
* @param role - employee | hr
*/
const resolveLocalizedDefaultQuestions = (role: TrainingChatQuestionRole): string[] => {
// tm 在严格 locale 类型下可能推断为 never;运行时仍为 string[]
const raw = i18n.global.tm(`chat.training.defaultQuestions.${role}`) as unknown;
if (Array.isArray(raw)) {
return raw.map((item: unknown) => String(item || '').trim()).filter(Boolean);
}
return [];
};
export const DEFAULT_TRAINING_HR_CHAT_QUESTIONS = [
'现在有多少人参加了培训?',
'当前培训通过率是多少?',
'哪些员工还没有完成培训?',
'我想查看本月培训成绩统计',
];
/** @deprecated 兼容 Admin 表单旧引用:返回当前语言默认员工问题 */
export const DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS = resolveLocalizedDefaultQuestions('employee');
/** @deprecated 兼容 Admin 表单旧引用:返回当前语言默认 HR 问题(模块加载时快照) */
export const DEFAULT_TRAINING_HR_CHAT_QUESTIONS = resolveLocalizedDefaultQuestions('hr');
const asRecord = (value: unknown): Record<string, unknown> => (
value && typeof value === 'object' && !Array.isArray(value)
@@ -49,10 +56,12 @@ const normalizeTrainingChatQuestionList = (value: unknown): string[] => {
.filter(Boolean);
};
const getDefaultQuestions = (role: TrainingChatQuestionRole) => (
role === 'hr'
? cloneQuestions(DEFAULT_TRAINING_HR_CHAT_QUESTIONS)
: cloneQuestions(DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS)
/**
* 获取培训角色默认常见问题(按当前 i18n 语言实时解析)。
* @param role - employee | hr
*/
export const getDefaultTrainingChatQuestions = (role: TrainingChatQuestionRole): string[] => (
cloneQuestions(resolveLocalizedDefaultQuestions(role))
);
/**
@@ -69,7 +78,7 @@ export const resolveTrainingRoleChatQuestions = (
if (!matchedKey) {
return {
configured: false,
questions: getDefaultQuestions(role),
questions: getDefaultTrainingChatQuestions(role),
};
}
return {