771 Commits

Author SHA1 Message Date
64c292db82 Improve DOCX translation handling 2026-07-30 16:32:13 +08:00
20cf8f8188 perf: bump default chunk_size 1000 -> 6000 + log chunk stats
Root cause of 24-min translation: frontend default chunk_size was 1000
(upstream xunbu default), producing 78 requests for the client's WI
document (verified by running segments2json_chunks on the real file:
1000 -> 78 chunks, matches server log's '75 requests').

- index.html: default chunk_size 1000 -> 6000 (78 -> 13 requests, 6x
  fewer). 6000 is safe vs qwen3.6-plus 8-16K output limit, and gives
  the LLM MORE context (better terminology consistency). Slider range
  already allows up to 12000.
- segments_agent.py: log segment count / total chars / chunk_size /
  expected request count after chunking, so 'slow translation' reports
  can be diagnosed instantly (doc structure vs chunk size vs API latency).
2026-07-28 10:11:19 +08:00
13c8732c42 fix: add thinking diagnostic log + skip retry for code-only chunks
Two changes to finish off the slow-translation issue:

1. agent.py: log the resolved thinking config at Agent init. Lets
   operators confirm from task logs that the thinking-disable fix is
   actually running (e.g. 'field=extra_body, applied_value={enable_thinking: False}')
   — critical for distinguishing 'fix not deployed' from 'fix not enough'.

2. segments_agent.py: when the whole chunk returns identical to source,
   skip the retry if the source has fewer than two 4+ letter English
   words. Technical docs (this client's WI/PRD docs) have many chunks
   that are pure codes/numbers/abbreviations (FRM-QAD-SQM-018, HNB-020,
   V1.0) — LLM correctly returns them unchanged, but the old code
   retried 3x. 4-letter threshold avoids matching 3-letter abbrevs
   like FRM/QAD/HNB.
2026-07-27 18:54:44 +08:00
d252ac5de3 fix: thinking mode was never actually disabled (extra_body bug)
_add_thinking_mode set data["extra_body"]={"enable_thinking": False},
but extra_body is an OpenAI Python SDK convention that gets unwrapped
to top-level by the SDK. This project sends requests via httpx, so
extra_body was sent as a literal nested key that DashScope ignores —
qwen3.6-plus kept thinking ON, wasting 96% of output tokens on
reasoning (measured: 0.54K reasoning / 0.56K output) and inflating
a 3-min translation to 24-min.

Fix: when the field is extra_body (aliyuncs/google providers), merge
its dict into the top-level request body instead of nesting it.
2026-07-27 18:05:53 +08:00
746425528f fix: disable thinking and extend timeout for filename translation
qwen3.6-plus on DashScope uses extended thinking by default, causing
filename translation to timeout at 10s (reasoning tokens add latency).
- enable_thinking: false → skip CoT for this simple one-word task
- timeout: 10 → 30s as safety net for slower environments
2026-07-13 19:12:08 +08:00
4045d7faf2 fix: persist translated_filename_stem and pass it to printPdf
- _translate_filename_stem: add success/failure logging, include
  glossary terms in prompt for accurate proper noun translation
- task_state: store translated_filename_stem after translation
- status API: return translated_filename_stem to frontend
- printPdf: accept stem param, set document.title directly instead
  of fragile Content-Disposition header parsing
- Both printPdf call sites now pass task.translatedStem
2026-07-13 18:31:23 +08:00
b4538801ea feat: remove markdown_based workflow option from UI
Mineru/Docling PDF parsing requires tokens or heavy deps not available
on client server. Remove the option from dropdown, default to docx,
and stop auto-selecting markdown_based for unrecognized file types.
2026-07-13 18:07:19 +08:00
683050c927 fix: handle RFC 5987 filename*=UTF-8'' encoding in printPdf
Previous regex matched 'UTF-8' as filename when Content-Disposition
used extended notation. Now try filename*=UTF-8''<percent-encoded>
first, then fall back to plain filename="...".
2026-07-13 17:55:01 +08:00
e4641aee58 fix: set parent page title before print for correct PDF filename
Chrome/Edge uses parent page title (not iframe title) when printing
to PDF. Temporarily swap document.title to translated stem before
print(), restore it 1s later after dialog opens.
2026-07-13 17:51:54 +08:00
206ef091cc fix: use translated filename as PDF print title
Read Content-Disposition filename from the HTML download response,
strip the extension, inject it as <title> before printing. Browser
uses <title> as the filename when saving to PDF.
2026-07-13 17:06:14 +08:00
c770b7348d fix: hide PDF download button for PPTX workflow
PPTX→PDF via browser print produces plain text (no layout/images).
Hide the button when task.downloads.pptx exists to avoid confusing output.
2026-07-13 16:56:53 +08:00
424d5e01a8 feat: translate output filename to target language
Add _translate_filename_stem() which calls the configured LLM to
translate the filename stem before building the export map. Result:
磨粉.pdf translated to English → grinding.pdf (instead of 磨粉_translated.pdf).
Falls back to original stem on any API error with zero impact on translation flow.
2026-07-13 16:13:45 +08:00
d86d5c1c64 fix: 术语表上传/导入/导出全面修复+协同维护+离线保存
上传不触发问题:
- 原生file控件改为隐藏,由【导入CSV】按钮触发(triggerGlossaryImport)
- 折叠区和弹窗内都提供导入入口
- 导入后自动打开弹窗显示结果+提示导入条数

CSV解析鲁棒性:
- 用FileReader读UTF-8文本,Papa.parse(字符串)替代File对象,加手动parseCsvText兜底
- transformHeader剥离BOM+规范化,修复带BOM的CSV首列名变成zh导致中文列丢失
- normalizeGlossaryRow支持3列(zh/en/id)、2列任意组合、旧src/dst格式

协同维护+离线保存:
- loadGlossaryFromServer失败时从localStorage缓存回退
- saveGlossary先写localStorage再同步服务端,服务端失败提示"已保存到本机"
- openGlossaryModal用getOrCreateInstance复用实例避免重复创建

文案:
- glossaryHelp更新为三语说明+支持任意两列
- 新增glossaryImportBtn/glossaryImportNone/glossaryImportError/glossarySavedLocal

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-26 10:02:03 +08:00
dd3c1cfe05 fix: 术语表导入丢失中文列(BOM) + 导出改用数据库实际内容
- handleGlossaryFiles: 加 transformHeader 剥离BOM+规范化表头,
  修复Excel/PapaParse读取带BOM的CSV时第一列名变成 zh 导致中文列被丢弃
- exportGlossaryCsv: 改为从 /service/glossary 拉取数据库实际内容再导出,
  避免导出未保存的本地脏数据;导出文件加UTF-8 BOM保证Excel中文不乱码
- 导入成功后提示已导入条数并提醒保存

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-25 19:35:01 +08:00
51e51efd2a docs: 新增CLAUDE.md运维指南,含客户服务器更新步骤
- 客户服务器git pull+重启标准流程
- DashScope API Key IP绑定说明
- MT vs 通用模型选型建议
- 共享术语表/数据目录说明
- 本分支相对原项目的关键改动

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-25 19:24:11 +08:00
f2e6d847e2 feat: 全公司共享三语术语表(中/英/印尼),保存即默认引用
- glossary_store.py: 进程级单例JSON存储,原子写入+asyncio锁,DOCUTRANSLATE_GLOSSARY_PATH可配置
- lang_mapping.py: 三列(zh/en/id)与{src:dst}互转,按目标语言自动取列;兼容旧2列CSV
- app.py: 新增GET/POST /service/glossary路由
- environment.py: 新增DOCUTRANSLATE_GLOSSARY_PATH环境变量
- index.html: 弹窗改为可编辑3列表+增删行+保存/导入/导出CSV;页面打开自动加载共享术语表;
  翻译时前端按to_lang编译为{src:dst},payload.glossary_dict契约不变
- i18nData.json: 三语新增术语表相关UI文案
- 翻译管线零改动:MT走translation_options.terms,非MT走system prompt注入

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-25 19:18:51 +08:00
2d39c009cf fix: MT模式改用JSON批处理+逐条回退,兼顾速度和可靠性
- MT模式: JSON批处理(616段→~12 chunks)
- 自动检测未翻译段(原文==译文),逐条回退重译
- 比纯逐条快约10倍,比纯批处理可靠

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 16:44:34 +08:00
4893163221 fix: 彻底移除MT批处理,qwen-mt模型会破坏所有文本分隔符
日志证实: \n\n---\n\n分隔符被MT模型破坏率82%(28/34批次)
MT模型逐条翻译是唯一可靠方案,无法批处理

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 16:39:47 +08:00
4f6bd1bc7b fix: MT批处理增加计数校验,不匹配时自动逐条回退
- MT_BATCH_SEP改为\n\n---\n\n,MT模型更不容易破坏
- _apply_mt_batch_results: 校验每批split count是否匹配预期
- 不匹配时标记为mismatched,_retranslate_mismatched逐条重译
- 批处理速度+逐条可靠性,两全兼顾

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 16:10:14 +08:00
a8b8c416dd fix: MT批处理+原项目功能合并,616段→21批
- segments_agent.py: MT模式用\n\n自然段落分隔批处理替代逐条发送
  _batch_segments_for_mt: 按chunk_size分批,\n\n连接段落
  _mt_batch_result_handler: 按\n\n拆分翻译结果回映射
  616段→21批(减少96.6% API调用),翻译速度从~6分钟→~1分钟
- docx_translator.py: 合并原项目功能
  +is_instr_text_run: 跳过w:instrText域代码,防止TOC/页码被破坏
  +_decrypt_if_needed: 支持密码加密的docx
  +office_password配置项

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 15:49:01 +08:00
4cf1a8c67d fix: MT模式改为逐条翻译,彻底消除标记依赖和29.4%内容丢失
- MT模式不再打包segment为<<<SEG:n>>>标记格式
- 改为每个segment一次纯文本API调用,1:1映射,零标记零解析
- 删除_chunk_to_mt_prompt/_parse_mt_response/_result_handler_mt等~100行死代码
- 新增_mt_simple_result_handler/_mt_simple_error_handler
- 非MT模式(JSON批处理)不受影响

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 15:20:06 +08:00
52bb8858c8 fix: 翻译前合并相邻同格式Run,解决Word微观Run碎片导致的格式混乱
- 新增_run_format_key(): 生成Run格式签名(bold/italic/size/color/font)
- 新增_merge_adjacent_runs(): 合并相邻同格式Run,减少Run碎片
- P91从42个Run合并为4个(2格式交替),P92从50个合并为1个
- 合并后翻译比例分配不再丢失内容和格式

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 15:00:31 +08:00
7f02abae0e fix: 印尼语在未更新i18nData.json的服务器上回退到en而非zh
- onMounted: 若id语言包缺失,自动使用en作为回退(而非显示中文)
- t(): 默认回退语言从zh改为en(英语比中文更通用)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 14:53:25 +08:00
97b7b20565 fix: 印尼语fallback缺失 + docx格式100%保留
- index.html: catch块增加id回退、setLang动态更新title、标题栏初始化
- docx_translator.py: 从分段翻译改为段落级翻译,Run结构100%保留
  删除SIGNIFICANT_STYLES/is_tab_run/_process_element_children等~120行死代码

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 14:43:54 +08:00
8a5f62342a fix: MT模式翻译残留、docx格式丢失、语言切换器及provider域名修复
- provider.py: 域名匹配改为包含匹配,覆盖dashscope-intl国际站
- segments_agent.py: MT模式改用<<<SEG:n>>>纯文本标记替代JSON,避免qwen-mt模型原文残留
- docx_translator.py: _apply_translation改为按字符比例分配译文到各Run,保留原始格式
- i18nData.json: vi(越南语)替换为id(印尼语),含完整175键翻译
- index.html: 语言切换器移至顶部标题栏,新增浏览器语言自动检测

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-08 14:07:13 +08:00
r-earth-or
9d8eacf0b4 feat:前端不显示模型api-key
隐藏GitHub链接
2026-04-15 13:57:05 +08:00
r-earth-or
47a3e9126a feat:自动根据环境变量填写前端输入项,支持术语表与领域知识 2026-04-07 13:20:43 +08:00
toy
9e82daa2a1 feat:兼容qwen-mt模型 2026-02-10 15:50:42 +08:00
xunbu
86a9958f58 添加依赖 2026-01-19 10:08:54 +08:00
xunbu
cd218a5ad0 增加regex 2026-01-19 09:52:22 +08:00
xunbu
6a2563bed6 修改备注 2026-01-18 23:56:08 +08:00
xunbu
2c7e879cd5 还原gemini的baseurl 2026-01-18 23:55:48 +08:00
xunbu
a6fe62420a 更新版本 2026-01-18 23:54:17 +08:00
xunbu
93009d70a9 优化pptx翻译效果 2026-01-18 23:50:58 +08:00
xunbu
5871f5dd85 修复gemini供应商标识 2026-01-18 21:13:57 +08:00
xunbu
8e91475e5c 修复gemini供应商标识 2026-01-18 21:04:00 +08:00
xunbu
95b71fd884 Merge branch 'main' of https://github.com/xunbu/docutranslate 2026-01-17 17:33:42 +08:00
xunbu
010ef31372 使用charset_normalizer替代chardet 2026-01-17 17:32:25 +08:00
xunbu
e502fa3a81 Merge pull request #21 from dominhhieu1405/main
Add Vietnamese language support.
2026-01-13 11:20:24 +08:00
Luce
c83a5ec906 Add Vietnamese 2026-01-13 00:47:35 +07:00
Luce
f112da27a4 Add Vietnamese localization strings to i18nData.json 2026-01-13 00:34:50 +07:00
Luce
e16a6fa3ae Add Vietnamese language link to README 2026-01-13 00:25:49 +07:00
Luce
d91a523582 Add Vietnamese language link to README 2026-01-13 00:25:34 +07:00
Luce
a9d761ea10 Add Vietnamese language link to README 2026-01-13 00:25:12 +07:00
Luce
408116b963 Add Vietnamese README with project details 2026-01-13 00:24:46 +07:00
xunbu
96e9404a76 优化html目录生成效率 2026-01-11 19:31:50 +08:00
xunbu
d04fb90314 update 2026-01-11 13:50:44 +08:00
xunbu
253eb00510 update 2026-01-11 13:38:45 +08:00
xunbu
3f827067fe update 2026-01-11 13:03:31 +08:00
xunbu
98ac573a13 修复术语表问题 2026-01-11 13:03:02 +08:00