feat: enhance localization support for KnowledgeFAQ import and conversation error messages

This commit is contained in:
mlogclub
2026-06-02 20:12:04 +08:00
parent 30b4c504d9
commit 77be1b4f5e
4 changed files with 175 additions and 2 deletions
+74
View File
@@ -104,6 +104,71 @@ func TestTranslateKnownMessageSupportsFormattedMessages(t *testing.T) {
message: "登录结果不能为空",
want: "Sign-in result is required.",
},
{
name: "directory not found",
message: "目录不存在",
want: "Directory not found.",
},
{
name: "directory has docs",
message: "该目录下存在文档,无法删除",
want: "This directory contains documents and cannot be deleted.",
},
{
name: "move documents",
message: "请选择要移动的文档",
want: "Select documents to move.",
},
{
name: "move faqs across knowledge bases",
message: "只能移动当前知识库下的FAQ",
want: "Only FAQs in the current knowledge base can be moved.",
},
{
name: "single knowledge base reference",
message: "知识库已被 AI Agent「SalesBot」引用,请先解除绑定",
want: "This knowledge base is referenced by AI Agent \"SalesBot\". Remove the binding first.",
},
{
name: "multiple knowledge base references",
message: "知识库已被 3 个 AI Agent 引用,请先解除绑定",
want: "This knowledge base is referenced by 3 AI Agents. Remove the bindings first.",
},
{
name: "schedule conflict range",
message: "该客服组在 2026-06-02 09:00:00 至 2026-06-02 10:00:00 已存在排班",
want: "This agent team already has a schedule from 2026-06-02 09:00:00 to 2026-06-02 10:00:00.",
},
{
name: "faq import duplicated question",
message: "同一文件中标准问题重复,首次出现于第12行",
want: "The standard question is duplicated in the same file. It first appeared on row 12.",
},
{
name: "faq import existing question",
message: "标准问题已存在,已跳过",
want: "The standard question already exists and was skipped.",
},
{
name: "required param",
message: "参数:name不能为空",
want: "Parameter \"name\" is required.",
},
{
name: "mcp call failed",
message: "调用 MCP 工具失败: timeout",
want: "Failed to call MCP tool: timeout",
},
{
name: "wxwork unsupported outbound",
message: "当前暂不支持企业微信下行消息类型: voice",
want: "The current WeCom outbound message type is not supported yet: voice",
},
{
name: "wxwork callback missing",
message: "企业微信登录回调地址未配置",
want: "WeCom sign-in callback URL is not configured.",
},
}
for _, tt := range tests {
@@ -117,6 +182,15 @@ func TestTranslateKnownMessageSupportsFormattedMessages(t *testing.T) {
}
}
func TestTranslateKnownMessageKeepsChineseLocale(t *testing.T) {
t.Parallel()
message := "目录不存在"
if got := TranslateKnownMessage(LocaleZhCN, message); got != message {
t.Fatalf("TranslateKnownMessage() = %q, want %q", got, message)
}
}
func TestMiddlewareStoresLocale(t *testing.T) {
gin.SetMode(gin.TestMode)
router := gin.New()