Skip to content

fix(plugins): localize official ToolPkg UI text for non-Chinese locales - #615

Open
YunXi-Aurora wants to merge 19 commits into
AAswordman:mainfrom
YunXi-Aurora:fix/plugin-ui-i18n
Open

YunXi-Aurora wants to merge 19 commits into
AAswordman:mainfrom
YunXi-Aurora:fix/plugin-ui-i18n

Conversation

@YunXi-Aurora

@YunXi-Aurora YunXi-Aurora commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

变更说明

官方插件(buildin + external,共 16 个)的 UI 文案此前全部为中文硬编码,即使宿主语言为 English,进入插件页面仍显示中文。本 PR 为这些插件建立语言选择机制,并为每一条用户可见文案补上英文,中文原文逐字保留、zh 行为零变化。

机制

沿用宿主已注入的 getLang(),按两种场景落地:

  • Compose 组件内:const [locale] = ctx.useState("locale", "zh"); const en = locale.startsWith("en"),与 character_cards/src/ui/memory-status/index.ui.ts 既有范式一致。
  • 纯函数 / 非组件模块:统一封装 localized(zh, en) / isEnglishUi(),内部调用 getLang()。

所有文案均按「中文原文不动 + 新增英文分支」的方式逐处修改,未使用批量正则替换;拼接文案拆成两套完整句子(避免中英混排语序错误)。

覆盖范围

插件 文件 增/删
buildin/character_cards 19 +355 / −303
buildin/workflow 2 +165 / −142
buildin/change_review 1 +22 / −21
buildin/goal_mode 1 +7 / −5
external/sidebar_model_sites 3 +267 / −20
external/qqbot 2 +215 / −79
external/connector_hub 3 +214 / −75
external/waifu 4 +139 / −33
external/image_workbench 6 +136 / −40
external/subagents 6 +120 / −35
external/wechat 2 +97 / −79
external/proactive_messages 2 +78 / −43
external/permission_overlay 1 +51 / −20
external/task_status_pet 2 +45 / −34
external/ai_chat_presentation 1 +38 / −30
external/context_limiter 1 +10 / −5

合计 56 个文件,+1959 / −964,全部位于 plugins/packages/,无宿主代码、无构建产物、无依赖升级。

character_cards 此前只有 memory-status 一个文件做过本地化,其余 15 个 UI 文件(管理页、选择器、记忆设置、记忆工作区、群组执行弹窗、侧边栏等)完全没有 i18n 机制,本 PR 一并补齐。

本次改动不涉及 demo 示例插件(desktop_widget_demo、dino_runner 等)。

改动类型

  • Bug 修复
  • 新功能
  • 重构或性能改进
  • 文档或构建工具
  • 第三方依赖或许可证更新

影响范围

  • 平台:Android / iOS / Windows / macOS / Linux(纯插件层,与宿主平台无关)
  • 模块:plugins/packages/buildin/{character_cards,workflow,change_review,goal_mode}、plugins/packages/external/{qqbot,wechat,subagents,waifu,ai_chat_presentation,image_workbench,connector_hub,context_limiter,sidebar_model_sites,task_status_pet,permission_overlay,proactive_messages}

行为影响:中文环境显示与改动前完全一致(所有中文原文保留在原分支);英文环境由中文变为英文。无数据迁移、无配置变更、无对外接口变更。

验证

内置包解析为必需检查,覆盖 buildin 和 external,包括默认关闭的插件。任何包解析或 registerToolPkg 注册失败,构建失败,PR 不予合并。请记录以下命令的结果及 Package parsing 检查状态:

python plugins/tools/sync_plugin_packages.py --source runtime --no-hot-reload
环境:Linux(Ubuntu 24.04 兼容),Node 24 + pnpm 12.23.0,clang 22 / lld,TypeScript 5.9.3

$ python3 plugins/tools/sync_plugin_packages.py --source runtime --no-hot-reload
...
PASS: subagents strict TypeScript; emitted plugin JavaScript
PASS: emitted archive module loading, composer registration and tool exports (controlled host)
PACKED: external/subagents/dist/subagents.toolpkg (34543 bytes, 16 files)
PACKED: buildin/character_cards.toolpkg (typed browser IIFE, exact executable tools metadata, public_api, all source modules included)
PACK: 31 个(buildin 7 + external 24)   COPY: 27 个
产出:core/crates/runtime/application/assets/plugins 下 40 个 .toolpkg + 18 个 .js
Done in 6m 13.9s using pnpm v12.23.0
errors = 0

说明:上述 40 个包全部通过 pnpm run pack:toolpkg 打包(含 tsc 类型检查),无一处报错。

脚本最后一步的生产解析器门禁 plugin_parse_gate 在本机未跑完:我自己的 40 分钟超时把 cargo 编译中途中断(EXIT=143,SIGTERM),属我的调度失误而非代码缺陷,本机磁盘余量也不足以完成该 crate 的依赖下载与编译。该项已由本 PR 的 Package parsing 检查完整覆盖并通过(run 47144570806,commit c887a8afc):

Step: Parse all bundled packages with the production loader   success
$ .venv/bin/python plugins/tools/sync_plugin_packages.py --source runtime --no-hot-reload

PASS: subagents strict TypeScript; emitted plugin JavaScript
PASS: emitted archive module loading, composer registration and tool exports (controlled host)

running 3 tests
test ...plugin_parse_gate::bundled_packages_parse ... PARSED: buildin/ai_chat.js
PARSED: external/worldbook.toolpkg
PACKAGE-PARSE-PASSED: 58 artifacts
ok
test ...plugin_parse_gate::child_parse_errors_reject_the_archive ... ok
test ...plugin_parse_gate::registration_requires_exported_callbacks ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 174 filtered out; finished in 2.75s

Done. source=runtime, copied=18, packed=40, deleted=0, dry_run=False

即 40 个 toolpkg + 18 个 .js 共 58 个产物全部通过生产解析器与 registerToolPkg 注册引擎校验,0 失败。

另外单独跑过的验证:

$ tsc -p tsconfig.json   # 每个改动插件的 pack:toolpkg 内含 check 步骤
子代理 / image_workbench / workflow / character_cards 等全部类型检查通过,0 error

截图或日志

英文界面实测(宿主语言设为 English,安装本分支构建的 debug APK):

页面 结果
AI Proactive Messages 全英文
Task Status Cat 全英文
External Connectors 全英文
QQ Bot Settings 全英文
WeChat Bot Settings 全英文

AI Proactive Messages
Task Status Cat
External Connectors
QQ Bot Settings
WeChat Bot Settings

未逐插件截图(16 个插件页面较多)。中文界面回归由代码层面保证:每条文案的中文分支保留原字符串。

已知残留(不在本 PR 范围)

External Connectors 的会话列表标题仍是中文(如 QQ 私聊 xxxx)。该文案由 bot 插件在数据层生成并持久化(qqbot/src/service.ts、qqbot/src/channel-store.ts、wechat/src/service.ts、wechat/src/channel-store.ts 创建会话时写入 title 字段),不是 Compose 渲染文本。改动它会影响已落库的会话记录(新旧标题混排)并触及 connectors.v1 的跨插件数据约定,因此单独处理更安全。如需要,我可以另开 PR 一并解决。

提交者确认

  • 全部内置及官方扩展包通过生产解析器和注册引擎校验,PR 的 Package parsing 检查通过。
  • 我已阅读 CONTRIBUTING.md。
  • 我已按 CLA.md 的流程签署协议,或提供了覆盖本次贡献的既有签署记录;所有共同贡献者均有相应签署记录。
  • 我拥有本次提交内容的版权或必要授权。
  • 我已保留第三方代码、资源及其许可证和版权声明。
  • 我没有提交密钥、令牌、个人数据或本地构建产物。
  • 我已更新受影响的文档和测试,或在上文说明了原因。

CLA 签署评论链接:#615 (comment)

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
…g test

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Site names, providers, descriptions and tags in the catalog were
hardcoded in Chinese, so non-Chinese hosts showed Chinese-only labels in
both the list and the viewer. The viewer's loading status strings were
also hardcoded.

Add English counterparts for every catalog field plus localizeSite()
and the getLocalized* lookup helpers, then route the list and viewer
through them and through a text(zh, en) helper keyed on getLang(). The
Chinese wording is unchanged; any non-zh locale now gets English.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
The memory status AlertDialog hardcoded its title and confirm label, so an English host showed Chinese text. Mirror the locale switch already used by the package's other screens.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
workspace.ui.ts already read the host locale but never derived an English branch, so the toolbar, opener menu and empty states stayed Chinese. goal_panel/index.ui.ts had no locale lookup at all. Both now switch on the same locale value the other screens in these packages use, leaving the Chinese text untouched.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
forms.ts renders every node editor field, and it had no language branch at all, so an English host showed Chinese labels, toasts and option text. Route the strings through a single en(english, chinese) helper backed by getLang, the same source main.ts already uses.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
The workflows screen rendered every label, dialog title, menu entry, empty state and relative timestamp in Chinese regardless of the host language. Route them through the shared en(english, chinese) helper so the Chinese text stays byte-identical while English hosts get English.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
The settings screen hardcoded every label, note, button and dialog string, so an English host showed a fully Chinese page. Read the host locale the same way the package's other screens do, keep the Chinese text byte-identical, and store the run status labels as zh/en pairs so the reply summary can follow the language.

Signed-off-by: Yunxi-Aurora <193331714+YunXi-Aurora@users.noreply.github.com>
Only the memory-status dialog was localized before, so the Characters screen,
memory menu, sidebar and selector kept rendering Chinese under an English
locale. This covers the remaining fifteen modules:

ui-management, ui-sidebar-native, ui-entity-native, ui-memory-workspace,
ui-memory-settings, ui-entity-preview, ui-initialization-recovery,
ui-memory-attachment, ui-memory-graph, ui-sidebar-native-layout,
ui-input-menu, ui-selector, ui-memory-menu, ui-contributions, ui-controls.

Components read the locale through ctx.useState("locale", "zh"); helpers that
run outside a composable scope call the host getLang() through the exported
isEnglishUi() in ui-contributions. Chinese literals stay byte-identical on the
zh branch, throw messages are untouched, and badge("\u5f53\u524d\u4f7f\u7528") keeps serving as the stable
cross-file token while the visible caption resolves per locale.
… group

The group execution modal rendered its title, status, submission line and three
buttons from hardcoded Chinese even though it receives ctx, and the sidebar built
its unbound section title inside a pure helper. Both reachable screens stayed
Chinese under an English locale.

group-execution/control.ts now derives en from ctx.useState("locale") and pairs
labels/outcomes tables; ui-sidebar.ts and group-avatar.ts use isEnglishUi() from
ui-contributions because they run outside a composable scope. Also localizes the
group avatar contentDescription, which screen readers announce.
@YunXi-Aurora

Copy link
Copy Markdown
Contributor Author

我已阅读并同意 Operit2 贡献者许可协议(CLA)1.0,确认有权作出其中的授权,并同意其适用于下列贡献及我此后向项目提交的贡献。
CLA 文本提交:7cf4a978445e801a6d7af55c42ef8c36623a7e3f
签署范围:#615
签署人:YunXi-Aurora

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

CLA 签署状态

当前 CLA 版本:7cf4a97(main 上 CLA.md 的最新提交)

作者 状态
@YunXi-Aurora ✅ 已签署(本 PR)

如何签署

按 CLA.md 第 7 条,在本 PR 发表一条独立评论:

我已阅读并同意 Operit2 贡献者许可协议(CLA)1.0,确认有权作出其中的授权,并同意其适用于下列贡献及我此后向项目提交的贡献。
CLA 文本提交:7cf4a978445e801a6d7af55c42ef8c36623a7e3f
签署范围:填写当前 PR 链接;如包含历史贡献,请逐项列出 PR 链接或提交 SHA
签署人:填写姓名;代表组织签署时,同时填写组织全称及代表身份

签署后本机器人会自动重新核验;签署记录以评论为准,勾选 PR 模板不代替签署。

@AAswordman

Copy link
Copy Markdown
Owner

感谢补齐官方插件的英文文案,这部分工作很有帮助。不过目前的语言组织方式建议在合并前再调整一下:像 workflow/src/ui/forms.ts 中的 en("Node reference", "引用节点"),以及各处 en ? "..." : "...",仍然把中英文文案直接放在 UI / 业务代码里,语言选择逻辑也分散在多个文件中。

这样能解决当前的中英文显示问题,但后续如果增加日语、法语等语言,就需要重新修改大量调用点,继续扩展参数或条件分支。翻译、检查缺失文案和统一回退规则也会越来越困难。因此我觉得目前这种直接铺开双语分支的方式不太适合作为后续多语言支持的基础。

建议每个插件使用独立的 src/lang.ts,按语言代码集中维护文案,UI / 业务代码只引用有类型约束的文案 key。例如(简化示范):

// src/lang.ts
const zh = {
  nodeReference: "引用节点",
  createUpstreamFirst: "请先创建上游节点",
};

type Messages = { [K in keyof typeof zh]: string };

const en: Messages = {
  nodeReference: "Node reference",
  createUpstreamFirst: "Create an upstream node first",
};

const ja: Messages = {
  nodeReference: "ノード参照",
  createUpstreamFirst: "先に上流ノードを作成してください",
};

const messages: Record<string, Messages> = { zh, en, ja };

export function lang(locale: string): Messages {
  const code = locale.trim().toLowerCase().replace(/_/g, "-");
  return messages[code] ?? messages[code.split("-")[0]] ?? en;
}
// src/ui/forms.ts
import { lang } from "../lang";

// 在渲染时使用当前宿主语言;组件内应沿用宿主的 locale 状态,
// 让切换语言后的重新渲染取得最新文案。
const strings = lang(getLang());
ctx.UI.Text({ text: strings.nodeReference });
void ctx.showToast(strings.createUpstreamFirst);

这样新增语言时,主要补充 lang.ts 中的字典和注册项即可,已有 UI 调用无需逐处修改;Messages 也能在类型检查时发现新语言缺少的 key。带参数的文案可以同样集中定义为完整句子的模板或函数,避免在调用点拼接语序。

看到 waifu 已经开始抽出独立的 ui/i18n.ts,这个方向是好的;建议本次统一整理为独立的 lang.ts,并把 [中文, 英文] 的位置数组也改成按语言代码组织的字典。默认语言和回退规则可以统一约定,上面的英文回退只是示例。辛苦再调整一下这层结构,后续扩展和维护会更方便,谢谢!

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants