消息渠道的消息支持多语言

This commit is contained in:
xintaofei
2026-03-31 13:49:16 +08:00
parent f2a53acc9d
commit f06360a59d
24 changed files with 1319 additions and 102 deletions

View File

@@ -1,21 +1,25 @@
use super::i18n::{self, Lang};
use super::types::{MessageLevel, RichMessage};
pub fn format_turn_complete(agent_type: &str, stop_reason: &str) -> RichMessage {
pub fn format_turn_complete(agent_type: &str, stop_reason: &str, lang: Lang) -> RichMessage {
let reason = match stop_reason {
"end_turn" => "正常结束",
"cancelled" => "已取消",
"end_turn" => i18n::stop_reason_end_turn(lang),
"cancelled" => i18n::stop_reason_cancelled(lang),
_ => stop_reason,
};
RichMessage::info(format!("{agent_type} 会话已完成"))
.with_title("会话完成")
.with_field("结束原因", reason)
RichMessage::info(i18n::turn_complete_body(lang, agent_type))
.with_title(i18n::turn_complete_title(lang))
.with_field(i18n::stop_reason_label(lang), reason)
}
pub fn format_agent_error(agent_type: &str, message: &str) -> RichMessage {
pub fn format_agent_error(agent_type: &str, message: &str, lang: Lang) -> RichMessage {
RichMessage {
title: Some("代理错误".to_string()),
body: format!("{agent_type} 发生错误"),
fields: vec![("错误信息".to_string(), message.to_string())],
title: Some(i18n::agent_error_title(lang).to_string()),
body: i18n::agent_error_body(lang, agent_type),
fields: vec![(
i18n::error_message_label(lang).to_string(),
message.to_string(),
)],
level: MessageLevel::Error,
}
}
@@ -28,31 +32,37 @@ pub struct DailyReportData {
pub key_activities: Vec<String>,
}
pub fn format_daily_report(report: &DailyReportData) -> RichMessage {
let mut body = format!("今日编码活动汇总 ({})", report.date);
pub fn format_daily_report(report: &DailyReportData, lang: Lang) -> RichMessage {
let mut body = i18n::daily_report_summary(lang, &report.date);
body.push_str(&format!("\n\n会话总数: {}", report.total_conversations));
body.push_str(&format!(
"\n\n{}",
i18n::total_sessions(lang, report.total_conversations)
));
if !report.conversations_by_agent.is_empty() {
body.push_str("\n\n按代理分布:");
body.push_str(&format!("\n\n{}", i18n::by_agent_label(lang)));
for (agent, count) in &report.conversations_by_agent {
body.push_str(&format!("\n {} - {} 个会话", agent, count));
body.push_str(&format!(
"\n {}",
i18n::agent_session_count(lang, agent, *count)
));
}
}
if !report.projects_involved.is_empty() {
body.push_str(&format!(
"\n\n涉及项目: {}",
report.projects_involved.join(", ")
"\n\n{}",
i18n::projects_label(lang, &report.projects_involved.join(", "))
));
}
if !report.key_activities.is_empty() {
body.push_str("\n\n主要活动:");
body.push_str(&format!("\n\n{}", i18n::key_activities_label(lang)));
for activity in &report.key_activities {
body.push_str(&format!("\n{}", activity));
}
}
RichMessage::info(body).with_title("每日编码报告")
RichMessage::info(body).with_title(i18n::daily_report_title(lang))
}