DSH HUB
HomePlugin StorePlugin PacksCommunityRankingsResourcesPublish Guide
Plugin source
Back to catalog

r-ayin /

r-ayin/dsh-en2zh

Verified

Live English-to-Chinese translation of model output in the web UI - translation above, original kept aside - with an optional local MT engine and LLM fallback.

★ 0 Stars0 Forks0 IssuesN/A Community rating0 Confirmed installs
View on GitHubProject homepage
READMESource: main@9815c31e

dsh-en2zh — 模型输出英译中(沉浸式翻译)

把 DSH Web 会话里模型输出的纯英文内容(assistant 正文 + 思考/reasoning 块) 自动翻译成中文:译文在上、原文保留在旁(弱化为灰色小字);思考块折叠摘要行 也整体替换为中文(展开后译文 + 原文并列)。

翻译范围与跳过规则

处理 内容
✅ 翻译 assistant-step 下的 p / li / h1-h6 / blockquote;think 块的 thinkBody 与摘要行
⛔ 跳过 含中文/日文/韩文(中英混杂)、代码块(pre/code)、表格、路径/URL/标识符密集文本、少于 3 个单词的短文本、流式生成中的内容、用户消息、工具卡片
  • 纯英文判定:无 CJK 字符 + 字母占比 ≥55% + 技术词(含 / \ _ : = 扩展名 等)占比 ≤30%。
  • 稳定性双检:文本连续两轮扫描(约 1.5s)指纹不变才送翻,防流式半途文本。
  • 译文缓存:sha256 → 中文,落盘 ~/.dsh/en2zh/cache.jsonl,刷新页面/重复文本零成本秒回。

架构

  • host(src/host.mjs,纯 JS 零编译):/en2zh/api/{ping,translate} 路由 (loopback/trustedHosts 信任围栏,与 side-chat 同源实现);批量翻译 (≤5 段/次,<<#n>> 分隔协议,解析缺失自动单条回退);长文本按段落切块(≤3000 字符)。 模型路由:agentDefaultModel 默认选择 → 最近一次主模型调用(llm/stream 捕获)→ 第一个可用 provider。
  • client(src/client/index.ts → tsdown → lib/client.js):MutationObserver + 周期扫描, 状态机(watch/queued/sent/done/skip/failed,失败 30s 冷却重试 ≤3 次), 译文块插原文旁、React 重渲染自动清理配对节点;右下角「译中 ✓/✗」悬浮开关 (localStorage 记忆,关闭时全部还原原文显示)。

构建 / 注入

bash scripts/build.sh   # host 直拷 + 借用生态 tsdown 打 client(本机无 dsh 源码 checkout)
# 对 AI 说:dev_inject_plugin {"dir": "<this-plugin-dir>"}
# 改代码后:bash scripts/build.sh && dev_reload_package {"packageName": "dsh-en2zh"}

注入后浏览器刷新一次页面,client 模块才会加载。

调试

  • host 日志:~/.dsh/super-injector/dsh-en2zh.log
  • 路由自检:curl -X POST http://127.0.0.1:3080/en2zh/api/ping -d '{}' -H 'content-type: application/json'
  • 手工翻译:curl -X POST http://127.0.0.1:3080/en2zh/api/translate -H 'content-type: application/json' -d '{"items":[{"id":"t1","text":"Hello world, this is a test."}]}'
—/ 5

No ratings yet

Verified DSH bundle

Commit 9815c31ea458

Community comments

No comments yet. Be the first to write one.

DSH HUB

A community index for DSH plugins. Not an official GitHub or DeepSeek AI product.

CommunityResourcesAPIAbout