From 7579cf5609d219533119871c5b3098efaaa3424c Mon Sep 17 00:00:00 2001 From: xmanrui <841206367@qq.com> Date: Mon, 23 Feb 2026 22:56:07 +0800 Subject: [PATCH] feat: add i18n support for alert center --- app/alerts/page.tsx | 70 ++++++++++++++++++++++++--------------------- lib/i18n.tsx | 26 +++++++++++++++++ 2 files changed, 64 insertions(+), 32 deletions(-) diff --git a/app/alerts/page.tsx b/app/alerts/page.tsx index 6e19169..dc3ac8f 100644 --- a/app/alerts/page.tsx +++ b/app/alerts/page.tsx @@ -23,15 +23,23 @@ interface Agent { emoji: string; } -const RULE_DESCRIPTIONS: Record = { - model_unavailable: "模型不可用 - 当测试模型失败时触发", - bot_no_response: "Bot 长时间无响应 - 当机器人超过设定时间未响应时触发", - message_failure_rate: "消息失败率升高 - 当消息失败率超过阈值时触发", - cron连续_failure: "Cron 连续失败 - 当定时任务连续失败超过设定次数时触发", +const RULE_DESCRIPTIONS: Record> = { + zh: { + model_unavailable: "模型不可用 - 当测试模型失败时触发", + bot_no_response: "Bot 长时间无响应 - 当机器人超过设定时间未响应时触发", + message_failure_rate: "消息失败率升高 - 当消息失败率超过阈值时触发", + cron连续_failure: "Cron 连续失败 - 当定时任务连续失败超过设定次数时触发", + }, + en: { + model_unavailable: "Model Unavailable - Triggered when model test fails", + bot_no_response: "Bot Long Time No Response - Triggered when bot is inactive for set period", + message_failure_rate: "Message Failure Rate High - Triggered when failure rate exceeds threshold", + cron连续_failure: "Cron Continuous Failure - Triggered when cron jobs fail multiple times in a row", + }, }; export default function AlertsPage() { - const { t } = useI18n(); + const { t, locale } = useI18n(); const [config, setConfig] = useState(null); const [agents, setAgents] = useState([]); const [loading, setLoading] = useState(true); @@ -42,6 +50,8 @@ export default function AlertsPage() { const [lastCheckTime, setLastCheckTime] = useState(""); const [checkInterval, setCheckInterval] = useState(10); // 默认 10 分钟检查一次 + const ruleDescriptions = RULE_DESCRIPTIONS[locale as keyof typeof RULE_DESCRIPTIONS] || RULE_DESCRIPTIONS.zh; + // 加载配置 useEffect(() => { Promise.all([ @@ -67,7 +77,7 @@ export default function AlertsPage() { .then((data) => { if (data.results && data.results.length > 0) { setCheckResults(data.results); - setLastCheckTime(new Date().toLocaleTimeString("zh-CN")); + setLastCheckTime(new Date().toLocaleTimeString(locale === "zh" ? "zh-CN" : "en-US")); } }) .catch(console.error) @@ -80,7 +90,7 @@ export default function AlertsPage() { // 设置定时器 const timer = setInterval(checkAlerts, checkInterval * 60 * 1000); return () => clearInterval(timer); - }, [config?.enabled, checkInterval]); + }, [config?.enabled, checkInterval, locale]); const handleManualCheck = () => { setChecking(true); @@ -89,7 +99,7 @@ export default function AlertsPage() { .then((data) => { if (data.results && data.results.length > 0) { setCheckResults(data.results); - setLastCheckTime(new Date().toLocaleTimeString("zh-CN")); + setLastCheckTime(new Date().toLocaleTimeString(locale === "zh" ? "zh-CN" : "en-US")); } }) .catch(console.error) @@ -181,7 +191,7 @@ export default function AlertsPage() { if (!config) { return (
-

Failed to load alert config

+

{t("common.loadError")}

); } @@ -201,16 +211,16 @@ export default function AlertsPage() { {/* 检查间隔设置 */} {config.enabled && (
- 检查间隔: + {t("alerts.checkInterval") || "Check Interval"}:
)} @@ -221,7 +231,7 @@ export default function AlertsPage() { disabled={checking} className="px-4 py-2 rounded-lg bg-[var(--card)] border border-[var(--border)] text-sm hover:border-[var(--accent)] transition disabled:opacity-50" > - {checking ? "⏳ 检查中..." : "🔄 立即检查"} + {checking ? (locale === "zh" ? "⏳ 检查中..." : "⏳ Checking...") : (locale === "zh" ? "🔄 立即检查" : "🔄 Check Now")} )} 0 && (
-

⚠️ 告警触发 ({checkResults.length})

+

+ {locale === "zh" ? "⚠️ 告警触发" : "⚠️ Alerts Triggered"} ({checkResults.length}) +

{lastCheckTime && {lastCheckTime}}
    @@ -250,7 +262,7 @@ export default function AlertsPage() { {config.enabled && checking && (
    - ⏳ 正在检查告警... + {locale === "zh" ? "⏳ 正在检查告警..." : "⏳ Checking alerts..."}
    )} @@ -281,12 +293,7 @@ export default function AlertsPage() { {/* 接收告警的机器人 */}
    -

    - {t("alerts.receiveAgent") || "Receive Alert Agent"} -

    -

    - {t("alerts.receiveAgentDesc") || "Select which agent will receive alert notifications"} -

    +

    {t("alerts.receiveAgent") || "Receive Alert Agent"}

    {agents.map((agent) => (
    {rule.threshold !== undefined && (
    - {rule.id === "bot_no_response" ? "Timeout (s):" : - rule.id === "message_failure_rate" ? "Failure rate (%):" : - rule.id === "cron连续_failure" ? "Max failures:" : "Threshold:"} + {rule.id === "bot_no_response" ? (locale === "zh" ? "超时 (秒):" : "Timeout (s):") : + rule.id === "message_failure_rate" ? (locale === "zh" ? "失败率 (%):" : "Failure rate (%):") : + rule.id === "cron连续_failure" ? (locale === "zh" ? "最大失败数:" : "Max failures:") : + (locale === "zh" ? "阈值:" : "Threshold:")} - ✓ Saved + ✓ {locale === "zh" ? "已保存" : "Saved"}
    )} diff --git a/lib/i18n.tsx b/lib/i18n.tsx index adc6ae0..13e358a 100644 --- a/lib/i18n.tsx +++ b/lib/i18n.tsx @@ -21,6 +21,19 @@ const translations: Record> = { "nav.skills": "技能管理", "nav.alerts": "告警中心", + // alerts page + "alerts.title": "告警中心", + "alerts.subtitle": "配置系统告警和通知", + "alerts.enableAlerts": "启用告警", + "alerts.enableDesc": "开启/关闭所有告警通知", + "alerts.receiveAgent": "接收告警的机器人", + "alerts.rules": "告警规则", + "alerts.rulesDesc": "配置哪些条件会触发告警", + "alerts.triggered": "告警触发 ({count})", + "alerts.checking": "正在检查告警...", + "alerts.checkNow": "立即检查", + "alerts.checkInterval": "检查间隔", + // common "common.loading": "加载中...", "common.loadError": "加载失败", @@ -188,6 +201,19 @@ const translations: Record> = { "nav.skills": "Skills", "nav.alerts": "Alerts", + // alerts page + "alerts.title": "Alert Center", + "alerts.subtitle": "Configure system alerts and notifications", + "alerts.enableAlerts": "Enable Alerts", + "alerts.enableDesc": "Turn on/off all alert notifications", + "alerts.receiveAgent": "Receive Alert Agent", + "alerts.rules": "Alert Rules", + "alerts.rulesDesc": "Configure which conditions trigger alerts", + "alerts.triggered": "Alerts Triggered ({count})", + "alerts.checking": "Checking alerts...", + "alerts.checkNow": "Check Now", + "alerts.checkInterval": "Check Interval", + // common "common.loading": "Loading...", "common.loadError": "Failed to load",