fix(kanban): i18n wake messages — address review feedback on #54872

Addresses @tonydwb's review on PR #54872 (12:05 UTC, 2026-06-29):

  > the hardcoded Chinese text in the wake messages (lines 118-128 of
  > the diff) should be replaced with English or internationalized.
  > The rest of the codebase uses English for user-facing messages,
  > and hardcoded Chinese will confuse non-Chinese users. Consider
  > using a constants dict or the existing i18n infrastructure.

Used the existing i18n infrastructure (agent/i18n.py::t()) — the same
surface gateway/run.py and slash_commands.py already use for static
user-facing strings.

## Changes

- gateway/kanban_watchers.py: import `t` from agent.i18n; replace the
  hardcoded Chinese strings in the synthetic wake-up message with
  t("gateway.kanban.wake.*") lookups. Behavior unchanged for zh users
  (zh catalog preserves the original Chinese phrasing).

- locales/en.yaml: new `gateway.kanban.wake.*` baseline keys (English):
  completed / gave_up / crashed / timed_out / blocked / status_default
  / status_joiner / message (with {task_id} {status} {title}
  {assignee} {board} placeholders).

- locales/zh.yaml: Chinese translation of the new keys, preserving the
  exact wording the original code used (so existing zh users see no
  visible change).

- locales/{zh-hant,ja,de,es,fr,tr,uk,af,ko,it,ga,pt,ru,hu}.yaml: added
  the same key set with English fallback values. The i18n invariant
  test (tests/agent/test_i18n.py::test_catalog_keys_match_english)
  requires every catalog to carry the same key set as en.yaml; native
  translations can land incrementally without breaking users (the
  loader falls back to en.yaml per-key when a translation is missing,
  but the key must still exist).

## Verification

- scripts/run_tests.sh tests/agent/test_i18n.py
  tests/gateway/test_kanban_watchers_mixin.py
  tests/gateway/test_kanban_notifier.py
  tests/gateway/test_kanban_notifier_watcher_dispatch_gate.py
  → 60 passed, 0 failed (i18n catalog parity + placeholders parity +
  existing kanban notifier behavior).

- Manual: with HERMES_LANGUAGE=en, t("gateway.kanban.wake.completed")
  returns "completed"; with HERMES_LANGUAGE=zh, returns "已完成";
  with HERMES_LANGUAGE=ja (translation pending), falls back to
  "completed" per-key.
This commit is contained in:
张满良
2026-06-30 00:16:06 +08:00
committed by kshitij
parent c69643026a
commit 3545d74915
17 changed files with 159 additions and 11 deletions
+15 -11
View File
@@ -18,6 +18,8 @@ import time
from pathlib import Path
from typing import Any, Callable, Optional
from agent.i18n import t
# Match the logger run.py uses (logging.getLogger(__name__) where __name__ ==
# "gateway.run") so extracted log records keep their original logger name.
logger = logging.getLogger("gateway.run")
@@ -486,17 +488,19 @@ class GatewayKanbanWatchersMixin:
_title = (task.title if task else sub["task_id"])[:120]
_assignee = task.assignee if task else ""
_parts = []
if "completed" in _wake_kinds: _parts.append("已完成")
if "gave_up" in _wake_kinds: _parts.append("已放弃(重试次数耗尽)")
if "crashed" in _wake_kinds: _parts.append("崩溃(worker 异常退出),dispatcher 将重试")
if "timed_out" in _wake_kinds: _parts.append("超时,dispatcher 将重试")
if "blocked" in _wake_kinds: _parts.append("被阻塞,需要处理")
_status = ",".join(_parts) or "状态变化"
_synth = (
f"[kanban] 任务 {sub['task_id']} {_status}。\n"
f"标题: {_title}\n执行者: @{_assignee}\n"
f"看板: {board_slug}\n\n"
f"请检查结果或决定下一步动作。"
if "completed" in _wake_kinds: _parts.append(t("gateway.kanban.wake.completed"))
if "gave_up" in _wake_kinds: _parts.append(t("gateway.kanban.wake.gave_up"))
if "crashed" in _wake_kinds: _parts.append(t("gateway.kanban.wake.crashed"))
if "timed_out" in _wake_kinds: _parts.append(t("gateway.kanban.wake.timed_out"))
if "blocked" in _wake_kinds: _parts.append(t("gateway.kanban.wake.blocked"))
_status = t("gateway.kanban.wake.status_joiner").join(_parts) or t("gateway.kanban.wake.status_default")
_synth = t(
"gateway.kanban.wake.message",
task_id=sub["task_id"],
status=_status,
title=_title,
assignee=_assignee,
board=board_slug,
)
from gateway.session import SessionSource
from gateway.platforms.base import MessageEvent, MessageType