Skip to content

[FEATURE]: Auto-translate provider/upstream error messages in session view to app language / 会话视图中 provider/上游报错按应用语言自动翻译 #44209

Description

@cnfaxian

Describe the enhancement you want / 功能诉求

EN: When app language is set to non-English (e.g., 简体中文), provider/upstream error messages rendered as pink/red error parts in the session view are still shown as raw English from the upstream API. These messages interrupt the conversation and are incomprehensible without an external translator. Please translate these dynamic error bodies to the user's app language in place, ideally in real time (original English can be kept as a secondary line/tooltip for debugging).

中文: 当应用语言设为非英文(如简体中文)时,会话视图中以粉色/红色打断对话的 provider/上游报错仍直接显示上游 API 返回的英文原文,需借助外部翻译才能看懂。希望按应用语言原地实时翻译这些动态报错正文(可保留英文原文作为次行/tooltip 供排查)。


Current vs Expected / 现状与期望

EN Current: Pink error parts show raw upstream text, e.g.:

Users must copy to an external translator to understand; the conversation appears to have "crashed" with a foreign message.

EN Expected: When language = 简体中文, the same error part shows a Chinese translation in place, e.g. 请求限流:今日免费额度已达上限 / 上游请求失败:网关返回了无效的 JSON / 该模型在你所在地区不可用 (original English optionally kept as second line).

中文现状: 同上,均为英文原文中断对话,需手动复制到翻译软件。

中文期望: language = 简体中文 时同一位置直接显示中文译文,效果接近“实时翻译”。


Why existing i18n does not cover this / 为何现有国际化未覆盖

EN: Static UI strings are covered by packages/app/src/i18n/zh.ts + formatServerError / formatInitError in packages/app/src/pages/error.tsx and packages/app/src/utils/server-errors.ts. However dynamic provider bodies bypass that dictionary:

  • packages/opencode/src/provider/error.ts: message() extracts body.error.message / body.message and returns it verbatim (return \${msg}: ${errMsg}`/return msg`).
  • packages/app/src/utils/server-errors.ts: formatServerError() returns error.message directly for unrecognized errors.

#13647 fixed only one hard-coded Zen string ("free usage exceeded" → PR #13652, closed). #35896 tracks missing static keys in zh.ts (error messages / error chains as UI keys, not dynamic bodies). #21084 (CLI/TUI locale-aware strings) is closed as not planned — it also only covers static strings. A generic layer for dynamic bodies is still missing.

中文: 静态文案已由 zh.ts 覆盖,但动态 provider 正文经上述两个函数原文透传,不在词典中;#13647 仅修单条 Zen 固定文案、#35896 仅统计静态键缺失、#21084 已关闭且仅管静态文案,均未解决此类动态报错的翻译。


Proposed solutions / 建议方案(任一即可,MVP 优先方案 1)

EN:

  1. Pattern-based mapping (offline, preferred MVP): Maintain a small regex → i18n-key map for high-frequency families and render via existing keys already in packages/console/app/src/i18n/en.ts (e.g., zen.api.error.rateLimitExceeded, zen.api.error.regionNotAllowed, zen.api.error.subscriptionQuotaExceeded, zen.api.error.insufficientBalance, zen.api.error.trialEnded). Unknown bodies fall back to raw English. This is offline, zero latency, and follows the lightweight MVP philosophy of [FEATURE]: add locale-aware CLI and TUI strings to packages/opencode #21084.
  2. Optional translation passthrough: When language != en, pipe the body through a translation hook before rendering (no hard dependency on an MT API — dictionary + fallback suffices for MVP; full MT can be a future enhancement).
  3. Keep original English as second line / responseBody for debugging.

中文:

  1. 离线正则家族映射(推荐 MVP): 为高频家族(限流/额度/地区/网关/认证/上下文超限)建正则→i18n-key 映射,复用 console/app/src/i18n/en.ts 已有 key,无匹配则回退英文;离线、零延迟,符合 [FEATURE]: add locale-aware CLI and TUI strings to packages/opencode #21084 轻量 MVP 思路。
  2. 可选翻译透传: 非英文时将正文经翻译钩子后再渲染(MVP 可仅词典兜底,无需强制接翻译 API;完整机器翻译可作后续增强)。
  3. 保留英文原文作次行/responseBody 便于排查。

Benefits / 收益

EN: Makes Desktop usable for non-English users without leaving the app; reuses the existing lightweight i18n direction (no heavy framework); fixes a recurring pain point reported in #33318 / #8796 / #40587 / #21336 where users hit rate-limit / region / upstream-JSON errors and cannot understand them.

中文: 中文用户无需跳出应用即可看懂报错;复用现有轻量 i18n 方向,无需重框架;解决上述 issue 中反复出现的限流/地区/网关报错看不懂、误以为“对话崩了”的问题。


Related / 关联 Issue

Closes gap left by #13647 and #35896. Relates to #7170 / #15800 / #21084 / #32514 / #8796 / #40587 / #41518 / #33318 / #21336 / #13318.


Environment / 环境

  • OpenCode Desktop 1.18.x, Windows 11, app language = 简体中文
  • Providers: OpenCode Zen (free-models-per-day-stealth), opencode-go relay, etc.

Additional context / 补充说明

EN: Community workarounds exist (opencode-zh-desktop via CDP injection, opencode-zh-plugin via system prompt) but they only cover static UI strings, not dynamic provider bodies — which is precisely the gap this request fills.

中文: 社区方案(opencode-zh-desktop CDP 注入、opencode-zh-plugin 提示词中文化)均仅覆盖静态界面文案,无法覆盖此类动态报错正文,正是本诉求要填补的空白。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions