Repository navigation
fix(plugins): localize official ToolPkg UI text for non-Chinese locales - #615
YunXi-Aurora wants to merge 19 commits into
Conversation
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.
|
我已阅读并同意 Operit2 贡献者许可协议(CLA)1.0,确认有权作出其中的授权,并同意其适用于下列贡献及我此后向项目提交的贡献。 |
CLA 签署状态当前 CLA 版本:
如何签署按 CLA.md 第 7 条,在本 PR 发表一条独立评论: 签署后本机器人会自动重新核验;签署记录以评论为准,勾选 PR 模板不代替签署。 |
|
感谢补齐官方插件的英文文案,这部分工作很有帮助。不过目前的语言组织方式建议在合并前再调整一下:像 这样能解决当前的中英文显示问题,但后续如果增加日语、法语等语言,就需要重新修改大量调用点,继续扩展参数或条件分支。翻译、检查缺失文案和统一回退规则也会越来越困难。因此我觉得目前这种直接铺开双语分支的方式不太适合作为后续多语言支持的基础。 建议每个插件使用独立的 // 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);这样新增语言时,主要补充 看到 |
变更说明
官方插件(
buildin+external,共 16 个)的 UI 文案此前全部为中文硬编码,即使宿主语言为 English,进入插件页面仍显示中文。本 PR 为这些插件建立语言选择机制,并为每一条用户可见文案补上英文,中文原文逐字保留、zh行为零变化。机制
沿用宿主已注入的
getLang(),按两种场景落地: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()。所有文案均按「中文原文不动 + 新增英文分支」的方式逐处修改,未使用批量正则替换;拼接文案拆成两套完整句子(避免中英混排语序错误)。
覆盖范围
合计 56 个文件,+1959 / −964,全部位于
plugins/packages/,无宿主代码、无构建产物、无依赖升级。character_cards此前只有memory-status一个文件做过本地化,其余 15 个 UI 文件(管理页、选择器、记忆设置、记忆工作区、群组执行弹窗、侧边栏等)完全没有 i18n 机制,本 PR 一并补齐。本次改动不涉及
demo示例插件(desktop_widget_demo、dino_runner等)。改动类型
影响范围
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检查状态:说明:上述 40 个包全部通过
pnpm run pack:toolpkg打包(含tsc类型检查),无一处报错。脚本最后一步的生产解析器门禁
plugin_parse_gate在本机未跑完:我自己的 40 分钟超时把 cargo 编译中途中断(EXIT=143,SIGTERM),属我的调度失误而非代码缺陷,本机磁盘余量也不足以完成该 crate 的依赖下载与编译。该项已由本 PR 的Package parsing检查完整覆盖并通过(run 47144570806,commitc887a8afc):即 40 个 toolpkg + 18 个 .js 共 58 个产物全部通过生产解析器与
registerToolPkg注册引擎校验,0 失败。另外单独跑过的验证:
截图或日志
英文界面实测(宿主语言设为 English,安装本分支构建的 debug APK):
未逐插件截图(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 一并解决。提交者确认
Package parsing检查通过。CLA 签署评论链接:#615 (comment)