dsh-bilingual-reader 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
9
9
  [![node](https://img.shields.io/badge/node-%3E%3D22.12-2f6f4f)](package.json)
10
10
 
11
- ![Bilingual reader: original on the left, translation on the right, code blocks intact, glossary and cache](docs/demo.jpg)
11
+ ![Bilingual reader: translation directly under each paragraph, code blocks intact, glossary and cache](docs/demo.jpg)
12
12
 
13
13
  ## Why
14
14
 
@@ -17,16 +17,18 @@ DSH already has 297 translation-related plugins, but most cover a single entry p
17
17
  This plugin replicates the core experience of Immersive Translate and Read Frog, but in a DSH-native way:
18
18
 
19
19
  - **Bilingual next to the original** — every paragraph keeps its translation underneath; no separate translation window.
20
+ - **Web page or pasted text** — fetch a public article, or switch to **Paste text** when a login wall or SPA blocks extraction.
21
+ - **Read while it translates** — finished paragraphs appear in place, and progress updates replace only the blocks that changed, so your scroll position stays put.
20
22
  - **Structure preserved** — code blocks, inline code, LaTeX, link URLs, tables and heading levels are protected; dropped tokens are detected and retried.
21
23
  - **Token-efficient** — blocks are batched into one request; translations are cached by `original + target language + glossary hash`.
22
- - **Reusable** — a glossary enforces consistent terms; bilingual Markdown exports; agents read and write the same data.
24
+ - **Reusable** — a glossary enforces consistent terms, and translations that miss a required term or look untranslated are flagged for review; bilingual Markdown exports; agents read and write the same data.
23
25
  - **Local-first** — data lives in `~/.dsh-bilingual-reader/`; no telemetry, no separate API key.
24
26
 
25
27
  ## Install
26
28
 
27
29
  Requires **DSH >= 0.2.0 < 0.3.0** and **Node.js >= 22.12**.
28
30
 
29
- From npm (after publishing):
31
+ From npm:
30
32
 
31
33
  ```sh
32
34
  dsh plugin --profile web add dsh-bilingual-reader
@@ -50,12 +52,16 @@ Restart DSH and open **Bilingual Reader** in the sidebar. The plugin uses the **
50
52
 
51
53
  ### Sidebar
52
54
 
53
- Paste a public article URL, choose the target language (Simplified Chinese, Traditional Chinese, English, Japanese, Korean) and click **Read and translate**.
55
+ Paste a public article URL, choose the target language (Simplified Chinese, Traditional Chinese, English, Japanese, Korean) and click **Read and translate**. If a page cannot be extracted, switch to **Paste text** and translate Markdown or plain text directly.
54
56
 
57
+ - **Inline** (default) — the translation sits directly under each paragraph, best for narrow windows and immersive reading.
55
58
  - **Bilingual** — original on the left, translation on the right.
56
- - **Original** / **Translation** — single-column reading.
57
- - **Glossary** — add terms such as `token → 令牌`; translations must use them.
59
+ - **Original** / **Translation** — single-column reading; the view choice is remembered.
60
+ - **Text size and position** — A− / A / A+ in the top bar; the setting is remembered, and each document reopens at your last scroll position. Opening the sidebar again resumes the last document; `?doc=<id>` opens a specific one, `?url=<link>` prefills a URL, and `start=1` begins translation.
61
+ - **Glossary** — add terms such as `token → 令牌`; translations must use them, **Retry this block** bypasses the cache for a fresh attempt, and JSON import/export makes the glossary easy to back up or move.
58
62
  - **Export bilingual Markdown** — headings, lists, tables and code blocks are kept.
63
+ - **Print** — reader layout with navigation, sidebar and action buttons hidden.
64
+ - **Copy translations** — copy all translated blocks as Markdown for notes or chat.
59
65
  - **Retry failed blocks** — completed blocks are not translated again.
60
66
 
61
67
  ### Command
@@ -82,9 +88,9 @@ The command returns a document id immediately; translation continues in the back
82
88
  2. Readability extracts the article; Turndown converts it to Markdown.
83
89
  3. `segmentMarkdown` splits it into blocks: headings, paragraphs, lists, tables and quotes are translatable; code fences, rules and image-only blocks are skipped.
84
90
  4. `protectInline` replaces inline code, LaTeX, link URLs, bare URLs and HTML tags with `⟦n⟧` tokens.
85
- 5. Up to 6 blocks / 3500 characters are sent per request; the model must return an ordered JSON array. A failed batch falls back to single-block requests.
91
+ 5. Up to 6 blocks / 3500 characters are sent per request; the model must return an ordered JSON array. A failed batch falls back to single-block requests, and 2 batches run at a time by default.
86
92
  6. Tokens are restored, heading prefixes are repaired, and translations are written to the cache by content hash.
87
- 7. Documents live under `~/.dsh-bilingual-reader/docs/<id>/`; the UI renders the bilingual view and exports bilingual Markdown.
93
+ 7. Documents live under `~/.dsh-bilingual-reader/docs/<id>/`; the UI defaults to inline bilingual view and exports bilingual Markdown.
88
94
 
89
95
  ## Configuration
90
96
 
@@ -94,7 +100,9 @@ The command returns a document id immediately; translation continues in the back
94
100
  | `DSH_BILINGUAL_TARGET_LANG` | `zh-CN` | Default target language |
95
101
  | `DSH_BILINGUAL_BATCH_BLOCKS` | `6` | Max blocks per request |
96
102
  | `DSH_BILINGUAL_BATCH_CHARS` | `3500` | Max characters per request |
103
+ | `DSH_BILINGUAL_CONCURRENCY` | `2` | Concurrent translation batches (1–4) |
97
104
  | `DSH_BILINGUAL_MAX_BLOCKS` | `400` | Max blocks per document |
105
+ | `DSH_BILINGUAL_MAX_TRANSLATE_CHARS` | `20000` | Pasted-text and ad-hoc translation limit |
98
106
  | `DSH_BILINGUAL_MAX_BYTES` | `5242880` | Page size cap |
99
107
  | `DSH_BILINGUAL_TIMEOUT_MS` | `20000` | Fetch timeout |
100
108
  | `DSH_BILINGUAL_PROXY` | environment proxy | Fetch proxy |
@@ -110,17 +118,29 @@ The command returns a document id immediately; translation continues in the back
110
118
 
111
119
  ## Limitations
112
120
 
113
- - Public pages only; login walls, SPAs and anti-bot pages may fail extraction and will suggest pasting the text.
121
+ - Public pages only; login walls, SPAs and anti-bot pages may fail extraction. Switch to **Paste text** to translate the body directly.
114
122
  - No PDF/EPUB/DOCX layout translation in v0.1; convert PDFs to Markdown first.
115
123
  - Does not translate assistant replies (covered by `dsh-bilingual` / `dsh-think-translate`); it focuses on web and document reading.
116
124
  - Translation quality depends on the DSH default model; malformed batch responses fall back to single blocks.
117
125
  - Cache entries are shared across documents; changing the glossary produces new cache keys.
118
126
 
127
+ ## FAQ
128
+
129
+ **Does this conflict with `dsh-reading-inbox`?** No. The inbox saves, organizes, searches and annotates; the bilingual reader fetches the article, translates it and shows the parallel text. With both installed, web documents get a **Save to reading inbox** action.
130
+
131
+ **What content is supported?** Public web pages, or Markdown/plain text pasted directly. PDF, EPUB and DOCX layout translation are out of scope; convert them to Markdown first.
132
+
133
+ **Which model does it use?** The DSH default model, with no separate API key. If the profile has no model, the UI explains it; translated documents remain readable.
134
+
135
+ **What does "glossary miss" mean?** The translation did not use the target term configured in the glossary. Edit the term and click **Retry this block** to bypass the cache for that block.
136
+
137
+ **Where is the data?** `~/.dsh-bilingual-reader/` by default, containing documents, cache and glossary; override it with `DSH_BILINGUAL_READER_DIR`.
138
+
119
139
  ## Development
120
140
 
121
141
  ```sh
122
142
  npm install
123
- npm test # 34 tests: segmentation, protection, prompts, cache, glossary, security, store/translator
143
+ npm test # 47 tests: segmentation, protection, prompts, cache, glossary, quality checks, security, store/translator, HTTP routes
124
144
  npm run verify # local HTTP fixture → fetch → translate → export → cache
125
145
  npm run dev # local UI with a demo model: http://127.0.0.1:4183/dsh-bilingual-reader/
126
146
  ```
@@ -129,10 +149,20 @@ Demo article for `npm run dev`: `http://127.0.0.1:4183/demo-article.html`.
129
149
 
130
150
  Architecture and data layout: [docs/architecture.md](docs/architecture.md).
131
151
 
152
+ ## Related
153
+
154
+ - [dsh-reading-inbox](https://github.com/bit0620/dsh-reading-inbox) — a local read-later inbox. When both plugins are installed, web documents get a **Save to reading inbox** action that hands the original URL to the inbox for archiving and search.
155
+
132
156
  ## Inspiration
133
157
 
134
158
  Product shape inspired by [Immersive Translate](https://github.com/immersive-translate/immersive-translate), [Read Frog](https://github.com/tomode1/read-frog), [NextAI Translator](https://github.com/nextai-translator/nextai-translator) and [Saladict](https://github.com/crimx/ext-saladict). The implementation is independent; no affiliation.
135
159
 
160
+ ## Release notes
161
+
162
+ - [v0.2.0](docs/release-v0.2.0.md): paste-text mode, reading-inbox handoff, translation quality warnings, text-size controls and a render cache.
163
+ - [v0.1.1](docs/release-v0.1.1.md): inline bilingual view by default, incremental progress rendering, parallel batches, cache and write consistency fixes.
164
+ - [v0.1.0](docs/release-v0.1.0.md): first release — web/document bilingual reading, glossary, cache, export and agent tools.
165
+
136
166
  ## License
137
167
 
138
168
  MIT
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
9
9
  [![node](https://img.shields.io/badge/node-%3E%3D22.12-2f6f4f)](package.json)
10
10
 
11
- ![双语阅读界面:左原文、右译文,代码块保持原样,术语表与缓存](docs/demo.jpg)
11
+ ![双语阅读界面:上下对照,译文在每段原文下方,代码块保持原样,术语表与缓存](docs/demo.jpg)
12
12
 
13
13
  ## 为什么做这个
14
14
 
@@ -17,16 +17,18 @@ DSH 里已经有 297 个和翻译相关的插件,但大多只覆盖一个入
17
17
  这个插件复刻的是 Immersive Translate / 陪读蛙最核心的体验,但按 DSH 的方式做:
18
18
 
19
19
  - **双语贴着原文**:每段原文下方就是译文,不跳转到另一个翻译窗口。
20
+ - **网页或粘贴文本**:公开文章直接抓正文;登录墙、SPA 可以切到“粘贴文本”,不离开阅读器。
21
+ - **边译边读**:完成的段落立即出现,进度更新只替换变化的段落,不会重置滚动位置。
20
22
  - **保结构**:代码块、行内代码、公式、链接 URL、表格、标题层级不翻译;模型丢失保护片段会被检测并重试。
21
23
  - **省 token**:多段合并成一次请求;按“原文 + 目标语言 + 术语表哈希”缓存,重复段落不再调用模型。
22
- - **可沉淀**:术语表强制统一译法;双语 Markdown 可导出;Agent 可以读写同一份数据。
24
+ - **可沉淀**:术语表强制统一译法,译文没用上指定术语或疑似未翻译时会标记出来;双语 Markdown 可导出;Agent 可以读写同一份数据。
23
25
  - **本地优先**:数据在 `~/.dsh-bilingual-reader/`,不发送遥测,不引入独立 API key。
24
26
 
25
27
  ## 安装
26
28
 
27
29
  要求 **DSH >= 0.2.0 < 0.3.0**、**Node.js >= 22.12**。
28
30
 
29
- 从 npm 安装(发布后):
31
+ 从 npm 安装:
30
32
 
31
33
  ```sh
32
34
  dsh plugin --profile web add dsh-bilingual-reader
@@ -50,12 +52,17 @@ dsh plugin --profile web add file:C:/path/to/dsh-bilingual-reader
50
52
 
51
53
  ### 侧栏
52
54
 
53
- 粘贴公开网页链接,选择目标语言(简体中文 / 繁體中文 / English / 日本語 / 한국어),点击“读取并翻译”。
55
+ 粘贴公开网页链接,选择目标语言(简体中文 / 繁體中文 / English / 日本語 / 한국어),点击“读取并翻译”;抓不到正文的页面可以切到“粘贴文本”,直接翻译 Markdown 或纯文本。
54
56
 
57
+ - **上下**(默认):原文在上,译文紧随其下,适合窄窗口和沉浸阅读。
55
58
  - **对照**:左原文、右译文。
56
- - **原文** / **译文**:单栏阅读。
57
- - **术语表**:添加 `token → 令牌` 这类术语,翻译时强制使用。
59
+ - **原文** / **译文**:单栏阅读;视图选择会记住。
60
+ - **字号与位置**:顶栏 A− / A / A+ 调整正文大小,选择会记住;每篇文档的阅读位置也会保存,重新打开回到上次处。
61
+ - **继续阅读**:再次打开侧栏会自动恢复上次文档;也支持 `?doc=<id>` 直接打开某一篇,`?url=<链接>` 预填链接,加 `start=1` 可直接开始翻译。
62
+ - **术语表**:添加 `token → 令牌` 这类术语,翻译时强制使用;质量提示旁的“重试此段”会绕过缓存重新翻译该段;支持 JSON 导入/导出,方便备份和换机器。
58
63
  - **导出双语 Markdown**:保留标题、列表、表格和代码块。
64
+ - **打印**:按阅读版式输出,自动隐藏导航、侧栏和操作按钮。
65
+ - **复制译文**:一键复制全部译文 Markdown,方便贴进笔记或对话。
59
66
  - 失败的段落可以“重试失败段”,不会重跑已完成的段落。
60
67
 
61
68
  ### 命令
@@ -82,9 +89,9 @@ dsh plugin --profile web add file:C:/path/to/dsh-bilingual-reader
82
89
  2. Readability 抽取正文,Turndown 转成 Markdown。
83
90
  3. `segmentMarkdown` 按块切分:标题、段落、列表、表格、引用可翻译;代码块、分隔线、纯图片跳过。
84
91
  4. `protectInline` 把行内代码、LaTeX、链接 URL、裸 URL、HTML 标签替换成 `⟦n⟧` 占位符。
85
- 5. 默认每 6 段 / 3500 字符合并成一次模型请求,要求返回同序 JSON 数组;失败拆成单段重试。
92
+ 5. 默认每 6 段 / 3500 字符合并成一次模型请求,要求返回同序 JSON 数组;失败拆成单段重试。默认同时跑 2 个批次。
86
93
  6. 译文恢复占位符;标题补回 `#` 前缀;按内容哈希写入缓存。
87
- 7. 文档写入 `~/.dsh-bilingual-reader/docs/<id>/`,前端渲染对照视图,导出时生成双语 Markdown。
94
+ 7. 文档写入 `~/.dsh-bilingual-reader/docs/<id>/`,前端默认以“上下对照”逐段呈现,导出时生成双语 Markdown。
88
95
 
89
96
  ## 配置
90
97
 
@@ -94,7 +101,9 @@ dsh plugin --profile web add file:C:/path/to/dsh-bilingual-reader
94
101
  | `DSH_BILINGUAL_TARGET_LANG` | `zh-CN` | 默认目标语言 |
95
102
  | `DSH_BILINGUAL_BATCH_BLOCKS` | `6` | 每次请求最多段落数 |
96
103
  | `DSH_BILINGUAL_BATCH_CHARS` | `3500` | 每次请求最多字符数 |
104
+ | `DSH_BILINGUAL_CONCURRENCY` | `2` | 同时翻译的批次数(1–4) |
97
105
  | `DSH_BILINGUAL_MAX_BLOCKS` | `400` | 单篇最多段落数 |
106
+ | `DSH_BILINGUAL_MAX_TRANSLATE_CHARS` | `20000` | 粘贴文本 / 即时翻译字符上限 |
98
107
  | `DSH_BILINGUAL_MAX_BYTES` | `5242880` | 页面大小上限 |
99
108
  | `DSH_BILINGUAL_TIMEOUT_MS` | `20000` | 抓取超时 |
100
109
  | `DSH_BILINGUAL_PROXY` | 环境代理 | 抓取代理 |
@@ -110,17 +119,29 @@ dsh plugin --profile web add file:C:/path/to/dsh-bilingual-reader
110
119
 
111
120
  ## 限制
112
121
 
113
- - 只支持公开页面;登录墙、SPA、反爬页可能提取失败,会提示改用粘贴正文。
122
+ - 只支持公开页面;登录墙、SPA、反爬页可能提取失败,可以切到“粘贴文本”直接翻译正文。
114
123
  - 第一版不做 PDF / EPUB / DOCX 版面翻译;PDF 可以先用其他工具转 Markdown。
115
124
  - 不翻译助手回复(已有 `dsh-bilingual` / `dsh-think-translate` 覆盖),专注网页与文档阅读。
116
125
  - 翻译质量取决于 DSH 默认模型;批量解析失败会自动降级到单段。
117
126
  - 缓存按段落命中,跨文档共享;修改术语表会产生新的缓存键。
118
127
 
128
+ ## 常见问题
129
+
130
+ **和 `dsh-reading-inbox` 冲突吗?** 不冲突:阅读箱负责收藏、归档、检索和批注,双语阅读负责抓正文、翻译和对照阅读。同时安装后,双语阅读的网页文档会出现“存入阅读箱”。
131
+
132
+ **支持哪些内容?** 公开网页,或直接粘贴 Markdown / 纯文本。PDF、EPUB、DOCX 版面翻译暂不支持,可以先把内容转成 Markdown。
133
+
134
+ **用的哪个模型?** DSH 默认模型,不需要单独的 API key;没有配置模型时界面会提示,已翻译文档仍可浏览。
135
+
136
+ **“术语未命中”是什么意思?** 译文没有使用术语表里为该词指定的译法。可以修改术语后点“重试此段”,会绕过缓存重新翻译该段。
137
+
138
+ **数据在哪里?** 默认 `~/.dsh-bilingual-reader/`,包括文档、缓存和术语表;可以用 `DSH_BILINGUAL_READER_DIR` 改位置。
139
+
119
140
  ## 开发
120
141
 
121
142
  ```sh
122
143
  npm install
123
- npm test # 34 项单测:切分、保护、提示词、缓存、术语表、安全、store/translator
144
+ npm test # 47 项单测:切分、保护、提示词、缓存、术语表、质量检查、安全、store/translator、HTTP 路由
124
145
  npm run verify # 本地 HTTP fixture → 抓取 → 翻译 → 导出 → 缓存
125
146
  npm run dev # 带示范模型的本地 UI:http://127.0.0.1:4183/dsh-bilingual-reader/
126
147
  ```
@@ -129,10 +150,20 @@ npm run dev # 带示范模型的本地 UI:http://127.0.0.1:4183/dsh-bili
129
150
 
130
151
  架构与数据格式见 [docs/architecture.md](docs/architecture.md)。
131
152
 
153
+ ## 相关项目
154
+
155
+ - [dsh-reading-inbox](https://github.com/bit0620/dsh-reading-inbox) — 本地阅读收件箱。同时安装后,双语阅读的网页文档会出现“存入阅读箱”,把原文链接交给阅读箱归档和后续检索。
156
+
132
157
  ## 灵感与致谢
133
158
 
134
159
  产品形态参考 [Immersive Translate](https://github.com/immersive-translate/immersive-translate)、[陪读蛙 Read Frog](https://github.com/tomode1/read-frog)、[NextAI Translator](https://github.com/nextai-translator/nextai-translator) 和 [Saladict](https://github.com/crimx/ext-saladict);代码为独立实现,与这些项目没有隶属关系。
135
160
 
161
+ ## 版本说明
162
+
163
+ - [v0.2.0](docs/release-v0.2.0.md):粘贴文本、阅读箱集成、翻译质量提示、阅读字号与渲染缓存。
164
+ - [v0.1.1](docs/release-v0.1.1.md):默认“上下对照”视图,逐段渐进更新,批量并行翻译,缓存与并发写入修正。
165
+ - [v0.1.0](docs/release-v0.1.0.md):首个版本,网页/文档双语阅读、术语表、缓存、导出与 Agent 工具。
166
+
136
167
  ## License
137
168
 
138
169
  MIT
@@ -11,11 +11,11 @@ URL ──fetchHtml──> HTML ──Readability + Turndown──> Markdown
11
11
  │
12
12
  ┌───────────────┬─────────────┴─────────────┐
13
13
  │ │ │
14
- cache 命中 批量翻译(默认 6 段 / 3500 字符) 单段重试
14
+ cache 命中 批量翻译(默认 6 段 / 3500 字符,2 批并行) 单段重试
15
15
  │ │ │
16
16
  └───────────────┴─────────────┬─────────────┘
17
17
  │
18
- doc.json + bilingual.md
18
+ doc.json(导出时生成 bilingual.md)
19
19
  ```
20
20
 
21
21
  ## 模块
@@ -29,7 +29,7 @@ URL ──fetchHtml──> HTML ──Readability + Turndown──> Markdown
29
29
  | `src/segment.js` | Markdown 块切分;代码块 / 分隔线 / 纯图片不翻译 |
30
30
  | `src/protect.js` | 行内代码、LaTeX、链接 URL、裸 URL、HTML 标签的占位保护与恢复 |
31
31
  | `src/prompt.js` | 批次切分、术语筛选、提示词、容错 JSON 解析 |
32
- | `src/translator.js` | 缓存优先、批量请求、单段回退、标题前缀修复、进度统计 |
32
+ | `src/translator.js` | 缓存优先、批量请求(默认 2 批并行)、单段回退、标题前缀修复、进度统计 |
33
33
  | `src/store.js` | 文档目录、任务状态、恢复中断、导出、术语表与缓存实例 |
34
34
  | `src/routes.js` | 回环限定的 HTTP API 与静态页面 |
35
35
  | `src/client.js` | DSH 侧栏入口 + iframe 主面板 |
@@ -50,7 +50,8 @@ URL ──fetchHtml──> HTML ──Readability + Turndown──> Markdown
50
50
  - 翻译任务在内存中运行;进程重启后 `recover()` 把 `running` 标记为 `interrupted`,用户可以重试。
51
51
  - 一个批次失败会拆成单段重试;单段仍失败只标记该段,不影响其他段落。
52
52
  - 模型丢失保护 token 时先重试单段;仍丢失则保留译文并给该段加 `warning`,不会静默删掉链接或代码。
53
- - 所有写文件使用临时文件 + rename,避免半截 JSON。
53
+ - 所有写文件使用唯一临时文件 + rename,避免半截 JSON;同一 store 的文档写入串行化,并行批次不会用旧快照覆盖新快照。
54
+ - HTTP 轮询返回的块 HTML 按内容哈希缓存,未变化段落不会重复执行 marked + sanitize-html;缓存有上限并在超限时清空。
54
55
 
55
56
  ## 安全边界
56
57
 
package/docs/demo.jpg CHANGED
Binary file
@@ -0,0 +1,47 @@
1
+ # dsh-bilingual-reader v0.1.0 / 首个版本
2
+
3
+ 面向 DeepSeek Harness 的双语阅读工作台:把网页或 Markdown 文档读成“原文 + 译文”的结构化双语页面,代码、公式、链接和表格保持原样。
4
+
5
+ A bilingual reading workbench for DeepSeek Harness: read web articles or Markdown documents with the translation beside each block while code, formulas, links and tables stay intact.
6
+
7
+ - GitHub: <https://github.com/bit0620/dsh-bilingual-reader>
8
+ - npm: <https://www.npmjs.com/package/dsh-bilingual-reader>
9
+ - License: MIT
10
+
11
+ ## 亮点 / Highlights
12
+
13
+ - **网页双语**:URL → Readability 正文 → 段落翻译 → 对照 / 原文 / 译文三种视图。
14
+ - **保结构**:代码块不翻译;行内代码、LaTeX、链接 URL、HTML 标签用占位符保护,丢失会重试。
15
+ - **省 token**:默认 6 段 / 3500 字符合并请求;按“原文 + 目标语言 + 术语表哈希”缓存。
16
+ - **术语表**:本地 `glossary.json`,翻译时强制统一译法,Agent 可增删查。
17
+ - **双语导出**:保留标题层级、列表、表格和代码块。
18
+ - **Agent 工具**:`bilingual_read_url`、`bilingual_translate`、`bilingual_status`、`bilingual_glossary`。
19
+ - **本地优先**:数据在 `~/.dsh-bilingual-reader/`,无遥测,无独立 API key,使用 DSH 默认模型。
20
+
21
+ ## 安装 / Install
22
+
23
+ ```sh
24
+ dsh plugin --profile web add dsh-bilingual-reader
25
+ ```
26
+
27
+ 或从 GitHub:
28
+
29
+ ```sh
30
+ dsh plugin --profile web add github:Bit0620/dsh-bilingual-reader
31
+ ```
32
+
33
+ 重启 DSH,从侧栏打开“双语阅读”。
34
+
35
+ ## 验证 / Verification
36
+
37
+ - 34 项单测:切分、保护、提示词解析、缓存、术语表、SSRF、正文抽取、store/translator 集成。
38
+ - `npm run verify`:本地 HTTP fixture → 抓取 → 翻译 → 导出 → 缓存,端到端通过。
39
+ - GitHub Actions Node 22/24 矩阵、`npm pack --dry-run` 全部通过。
40
+ - 独立 `DSH_HOME` + `dsh plugin add` 安装后,`--dump-config` 能组合出插件条目。
41
+
42
+ ## 限制 / Limitations
43
+
44
+ - 只支持公开页面;登录墙、SPA、反爬页可能提取失败。
45
+ - 第一版不做 PDF / EPUB / DOCX 版面翻译、浏览器扩展、对话回复翻译。
46
+ - 翻译质量取决于 DSH 默认模型;批量解析失败会降级到单段。
47
+ - 缓存按段落跨文档共享;修改术语表会产生新的缓存键。
@@ -0,0 +1,31 @@
1
+ # dsh-bilingual-reader v0.1.1 / 阅读体验与翻译速度
2
+
3
+ v0.1.1 把默认阅读方式改成“上下对照”:译文紧跟在每一段原文下面,和 README 里承诺的沉浸式阅读一致;同时让翻译并行运行、进度逐段呈现。
4
+
5
+ v0.1.1 makes inline bilingual reading the default — the translation sits directly under each paragraph — and speeds up translation with bounded concurrency and incremental progress rendering.
6
+
7
+ - GitHub: <https://github.com/bit0620/dsh-bilingual-reader>
8
+ - npm: <https://www.npmjs.com/package/dsh-bilingual-reader>
9
+ - 版本:`0.1.1`
10
+ - 升级:`dsh plugin --profile web add dsh-bilingual-reader` 或重新安装 GitHub 源
11
+
12
+ ## 变化 / Changes
13
+
14
+ - **上下对照成为默认视图**:原文在上、译文紧随其下;新增“上下 / 对照 / 原文 / 译文”四个视图,选择会记在浏览器里。
15
+ - **边译边读**:轮询只替换发生变化的那几个段落,不再整页重绘;滚动位置和文本选择不会被打断。
16
+ - **并行翻译**:默认同时跑 2 个批次(`DSH_BILINGUAL_CONCURRENCY` 可调,范围 1–4),长文完成得更快;进度仍按批次保存。
17
+ - **缓存一致性**:一轮翻译固定使用开始时的术语表哈希,运行中修改术语表不会把结果写到错误的缓存键;保护片段重试成功后会清掉旧警告。
18
+ - **并发写入更稳**:文档写入串行化,临时文件名加入随机后缀,避免并行批次在 Windows 上互相覆盖。
19
+
20
+ ## 验证 / Verification
21
+
22
+ - 36 项单测:新增批量并发上限、运行中术语表哈希一致性两项;原有切分、保护、提示词、缓存、术语表、SSRF、抽取、store/translator 测试全部通过。
23
+ - `npm run verify`:本地 HTTP fixture → 抓取 → 翻译 → 导出 → 缓存,端到端通过。
24
+ - 本地演示 UI:默认 `上下` 视图;翻译过程中检查了 DOM 节点,未变化的代码块保持同一个节点,只有译文段落被替换。
25
+ - GitHub Actions Node 22/24 矩阵与 `npm pack --dry-run` 通过。
26
+
27
+ ## 兼容性 / Compatibility
28
+
29
+ - 环境变量新增 `DSH_BILINGUAL_CONCURRENCY`(默认 `2`)。
30
+ - 文档格式和缓存格式不变;0.1.0 的文档可以直接打开。
31
+ - 仅支持 DSH `>=0.2.0 <0.3.0`、Node.js `>=22.12`。
@@ -0,0 +1,41 @@
1
+ # dsh-bilingual-reader v0.2.0 / 粘贴文本、阅读箱与质量提示
2
+
3
+ v0.2.0 补齐了“抓不到网页时怎么办”:可以直接粘贴 Markdown 或纯文本翻译;网页文档可以把原文一键交给 `dsh-reading-inbox` 归档;译文漏用术语或疑似未翻译时会标记出来。
4
+
5
+ v0.2.0 adds a paste-text mode, a one-click handoff to `dsh-reading-inbox`, glossary/untranslated quality warnings, persisted text-size controls and a render cache for polling.
6
+
7
+ - GitHub: <https://github.com/bit0620/dsh-bilingual-reader>
8
+ - npm: <https://www.npmjs.com/package/dsh-bilingual-reader>
9
+ - 版本:`0.2.0`
10
+ - 升级:`dsh plugin --profile web add dsh-bilingual-reader@0.2.0`
11
+
12
+ ## 变化 / Changes
13
+
14
+ - **粘贴文本**:侧栏可在“网页链接 / 粘贴文本”之间切换,直接翻译 Markdown 或纯文本;标题取第一行,文档照常保存、导出和重试。上限由 `DSH_BILINGUAL_MAX_TRANSLATE_CHARS` 控制(默认 20,000 字符),支持 Ctrl/Cmd+Enter 提交。
15
+ - **阅读箱集成**:检测到 `dsh-reading-inbox` 时,网页文档页显示“存入阅读箱”,通过阅读箱已有的 `?clip=<url>` 入口归档原文;粘贴文本文档不显示该按钮。
16
+ - **翻译质量提示**:译文与原文相同(长文本)、或术语表指定译法没有出现在译文中时,给该段加“可能未翻译 / 术语未命中”徽标;不改变通过状态,只提示复核。徽标旁的“重试此段”会绕过缓存重新翻译该段。
17
+ - **缓存也做质量检查**:命中的缓存译文同样会检查术语和未翻译情况,不会因为命中缓存而跳过提示。
18
+ - **术语表导入/导出**:术语表弹窗支持导出 JSON 和导入 JSON,导入按 source 合并(新增/更新/跳过计数),适合备份和换机器。
19
+ - **阅读字号与位置**:顶栏 A− / A / A+,90%–130% 五档,选择保存在 localStorage;每篇文档保存滚动位置,重新打开回到上次处。再次打开侧栏自动恢复上次文档,`?doc=<id>` 可深链到指定文档,`?url=<链接>&start=1` 可直接开始翻译。
20
+ - **打印**:文档页新增“打印”,打印样式隐藏导航、输入区、侧栏和操作按钮,按上下对照排版。
21
+ - **复制译文**:一键复制全部译文 Markdown,适合贴进笔记或对话。
22
+ - **无障碍**:进度条使用 `progressbar` 语义并同步进度值;输入方式按钮使用 `aria-pressed`;补充刷新按钮标签。
23
+ - **渲染性能**:轮询返回的块 HTML 按内容哈希缓存(上限 2000),未变化段落不再重复执行 marked + sanitize-html。
24
+
25
+ ## 验证 / Verification
26
+
27
+ - 47 项单测:新增质量检查、粘贴文本路由、单段强制重试、术语表导入/导出、文档列表/导出/删除、跨站请求拒绝;全部通过。
28
+ - `npm run verify`:本地 HTTP fixture → 抓取 → 翻译 → 导出 → 缓存,端到端通过。
29
+ - 本地 UI 实测:粘贴文本标题/段落/代码块切分正确;字号 110% 刷新后保持;术语未命中徽标显示;无阅读箱时“存入阅读箱”保持隐藏。
30
+ - 本地 `npm pack --dry-run` 通过;提交后由 GitHub Actions Node 22/24 矩阵复核。
31
+
32
+ ## 兼容性 / Compatibility
33
+
34
+ - 新增 HTTP 入口 `POST /dsh-bilingual-reader/api/read-text`,供界面使用;Agent 工具不变。
35
+ - 文档、缓存和术语表格式不变;0.1.x 的文档可以直接打开。
36
+ - 仍要求 DSH `>=0.2.0 <0.3.0`、Node.js `>=22.12`。
37
+
38
+ ## 说明 / Notes
39
+
40
+ - “存入阅读箱”只传递原文 URL,不复制双语正文;阅读箱负责归档与检索,双语阅读负责翻译与对照。
41
+ - 质量提示是启发式检查,不会因为提示而阻断导出或缓存。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bilingual-reader",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "面向 DeepSeek Harness 的双语阅读工作台:网页/文档 → 结构保留的双语对照,术语表与翻译缓存。",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -41,7 +41,7 @@
41
41
  "verify": "node scripts/verify.mjs",
42
42
  "dev": "node scripts/dev-server.mjs",
43
43
  "build:client": "node scripts/build-client.mjs",
44
- "prepare": "node scripts/build-client.mjs"
44
+ "prepack": "node scripts/build-client.mjs"
45
45
  },
46
46
  "dependencies": {
47
47
  "@mozilla/readability": "^0.6.0",
package/src/config.js CHANGED
@@ -54,6 +54,7 @@ export function loadConfig(env = process.env) {
54
54
  maxBlocks: positiveInt(env.DSH_BILINGUAL_MAX_BLOCKS, 400),
55
55
  batchBlocks: positiveInt(env.DSH_BILINGUAL_BATCH_BLOCKS, 6),
56
56
  batchChars: positiveInt(env.DSH_BILINGUAL_BATCH_CHARS, 3_500),
57
+ concurrency: positiveInt(env.DSH_BILINGUAL_CONCURRENCY, 2),
57
58
  maxTranslateChars: positiveInt(env.DSH_BILINGUAL_MAX_TRANSLATE_CHARS, 20_000),
58
59
  cacheLimit: positiveInt(env.DSH_BILINGUAL_CACHE_LIMIT, 20_000),
59
60
  glossaryLimit: positiveInt(env.DSH_BILINGUAL_GLOSSARY_LIMIT, 500),
package/src/glossary.js CHANGED
@@ -52,6 +52,39 @@ export class Glossary {
52
52
  return this.list()
53
53
  }
54
54
 
55
+ importTerms(terms) {
56
+ const incoming = Array.isArray(terms) ? terms : []
57
+ let added = 0
58
+ let updated = 0
59
+ let skipped = 0
60
+ for (const term of incoming) {
61
+ if (term === null || typeof term !== 'object') {
62
+ skipped += 1
63
+ continue
64
+ }
65
+ const source = cleanTerm(term.source)
66
+ const target = cleanTerm(term.target)
67
+ if (source === '' || target === '') {
68
+ skipped += 1
69
+ continue
70
+ }
71
+ const note = cleanTerm(term.note, 160)
72
+ const existing = this.terms.find(item => item.source.toLowerCase() === source.toLowerCase())
73
+ if (existing !== undefined) {
74
+ existing.target = target
75
+ existing.note = note
76
+ updated += 1
77
+ } else if (this.terms.length < this.limit) {
78
+ this.terms.push({ source, target, note })
79
+ added += 1
80
+ } else {
81
+ skipped += 1
82
+ }
83
+ }
84
+ this.terms.sort((a, b) => a.source.localeCompare(b.source))
85
+ return { terms: this.list(), added, updated, skipped }
86
+ }
87
+
55
88
  remove(source) {
56
89
  const cleanSource = cleanTerm(source)
57
90
  if (cleanSource === '') throw new Error('术语 source 不能为空')
package/src/quality.js ADDED
@@ -0,0 +1,30 @@
1
+ function normalize(text) {
2
+ return String(text ?? '')
3
+ .replace(/^#{1,6}\s+/, '')
4
+ .replace(/\s+/g, ' ')
5
+ .trim()
6
+ }
7
+
8
+ /**
9
+ * Non-blocking checks for a finished translation. These do not change the
10
+ * pass/fail state; they add a visible warning so a bad block is easy to review.
11
+ */
12
+ export function translationWarnings({ original, translation, glossary = [] } = {}) {
13
+ const warnings = []
14
+ const source = normalize(original)
15
+ const target = normalize(translation)
16
+ if (source.length >= 20 && source.toLocaleLowerCase() === target.toLocaleLowerCase()) {
17
+ warnings.push('译文与原文相同')
18
+ }
19
+ const haystack = target.toLocaleLowerCase()
20
+ for (const term of glossary) {
21
+ const sourceTerm = normalize(term?.source)
22
+ const targetTerm = normalize(term?.target)
23
+ if (sourceTerm === '' || targetTerm === '') continue
24
+ if (!source.toLocaleLowerCase().includes(sourceTerm.toLocaleLowerCase())) continue
25
+ if (!haystack.includes(targetTerm.toLocaleLowerCase())) {
26
+ warnings.push(`术语未使用:${sourceTerm}`)
27
+ }
28
+ }
29
+ return warnings
30
+ }