An agent skill for Codex, Claude Code, and OpenClaw that translates entire books (PDF/DOCX/EPUB) into any language using parallel subagents. Inspired by claude_translater.
$ npx -y skills add deusyu/translate-book --agent claude-code
What's inside
English | 中文
An agent skill for Codex, Claude Code, and OpenClaw that translates entire books (PDF/DOCX/EPUB) into any language using parallel subagents.
Inspired by claude_translater. The original project uses shell scripts as its entry point, coordinating the Claude CLI with multiple step scripts to perform chunked translation. This project restructures the workflow as an agent skill for Codex, Claude Code, and OpenClaw, using subagents to translate chunks in parallel, with manifest-driven integrity checks, resumable runs, and multi-format output unified into a single pipeline. As the project structure and implementation differ significantly from the original, this is an independent project rather than a fork.
Input (PDF/DOCX/EPUB)
│
▼
Calibre ebook-convert → HTMLZ → HTML → Markdown
│
▼
Split into chunks (chunk0001.md, chunk0002.md, ...)
│ manifest.json tracks chunk hashes
▼
Parallel subagents (8 concurrent by default)
│ each subagent: read 1 chunk → translate → write output_chunk*.md
│ batched to respect API rate limits
▼
Validate (manifest hash check, 1:1 source↔output match)
│
▼
Merge → Pandoc → HTML (with TOC) → Calibre → DOCX / EPUB / PDF
Each chunk gets its own independent subagent with a fresh context window. This prevents context accumulation and output truncation that happen when translating a full book in a single session.
run_state.json tracking glossary-sensitive re-translationebook-convert command must be available (download)pypandoc — required (pip install pypandoc)beautifulsoup4 — optional, for better TOC generation (pip install beautifulsoup4)npx skills add deusyu/translate-book -a codex -g
Or install it manually:
mkdir -p ~/.agents/skills
git clone https://github.com/deusyu/translate-book.git ~/.agents/skills/translate-book
Restart Codex if the newly installed skill does not appear.
npx skills add deusyu/translate-book -a claude-code -g
Or install it manually:
mkdir -p ~/.claude/skills
git clone https://github.com/deusyu/translate-book.git ~/.claude/skills/translate-book
openclaw skills install @deusyu/translate-book
In the Codex CLI or IDE extension, enter:
$translate-book Translate /path/to/book.pdf into Chinese.
Codex can also select the skill automatically when your request matches its description.
Ask the agent:
translate /path/to/book.pdf to Chinese
In Claude Code, you can also use the slash command:
/translate-book translate /path/to/book.pdf to Japanese
The skill handles the full pipeline automatically — convert, chunk, translate in parallel, validate, merge, and build all output formats.
All files are in {book_name}_temp/:
| File | Description |
|---|---|
output.md | Merged translated Markdown |
book.html | Web version with floating TOC |
book.docx | Word document |
book.epub | E-book |
book.pdf | Print-ready PDF |
tests/baselines/<book-id>/.tests/.artifacts/ and should not be committed.scripts/convert.py writes {book_name}_temp/ under the current working directory, run repository baseline tests from inside tests/.artifacts/ to keep generated files out of the repo root.mkdir -p tests/.artifacts
cd tests/.artifacts
python3 ../../scripts/convert.py ../baselines/standard-alice/standard-alice.epub --olang zh
# then run translation via the skill
python3 ../../scripts/merge_and_build.py --temp-dir standard-alice_temp --title "test"
Please open a detailed GitHub issue instead of starting with a pull request. This project is maintained as an AI-assisted skill pipeline, and changes need to be evaluated against the current orchestration rules, chunk/manifest contracts, baseline assets, and release flow in one maintainer-owned context.
Pull requests are not the preferred contribution path and may be closed in favor of an issue. If you already have a patch, include the idea, key diff, failing case, or verification notes in the issue; the maintainer may rework or split the implementation before merging.
A useful issue should include:
python3 scripts/convert.py /path/to/book.pdf --olang zh
Calibre converts the input to HTMLZ, which is extracted and converted to Markdown, then split into chunks (~6000 chars each). A manifest.json records the SHA-256 hash of each source chunk for later validation, and a source_fingerprint.json ties the temp dir to the exact source bytes it was built from — re-running against a replaced source file aborts instead of silently reusing stale chunks. Temp dirs created before fingerprinting are adopted with a warning on first re-run.
By default the working directory is {book_name}_temp/ under the current directory. Use --temp-root /path/to/work to keep the same leaf directory name under a different parent.
Each chunk is translated by a fresh-context sub-agent, which means the same proper noun can drift across multiple translations on a 100-chunk book. To fix this, the skill builds a glossary before translation:
<temp_dir>/glossary.json (hand-editable schema below).python3 scripts/glossary.py count-frequencies <temp_dir> to populate per-term frequencies (ASCII terms use word-boundary regex so cat doesn't match category; CJK terms use substring; single-CJK-char terms are rejected; aliases count toward the term they belong to).python3 scripts/glossary.py print-terms-for-chunk <temp_dir> chunkNNNN.md and injects the resulting 3-column (原文 | 别名 | 译文) markdown table into that chunk's prompt as a hard constraint. Term selection = (terms whose source OR any alias appears in this chunk) ∪ (top-N most-frequent book-wide).{
"version": 2,
"terms": [
{"id": "Manhattan", "source": "Manhattan", "target": "曼哈顿",
"category": "place", "aliases": [], "gender": "unknown",
"confidence": "medium", "frequency": 12,
"evidence_refs": [], "notes": ""}
],
"high_frequency_top_n": 20,
"applied_meta_hashes": {}
}
Existing v1 glossary.json files are auto-upgraded to v2 on first load. v2 forbids the same surface form (source or alias) appearing in two different terms; if a v1 file has polysemous duplicate sources, the upgrade aborts with a disambiguation message — fix the file by hand and reload.
Edit glossary.json between runs to fix translations; existing glossary.json is never overwritten — delete it to rebuild from scratch. scripts/run_state.py records which glossary terms each chunk used, so later glossary changes (including target, category, and aliases edits) only re-translate affected chunks after the state has been recorded.
The skill launches subagents in batches (default: 8 concurrent). Each subagent:
chunk0042.md)output_chunk0042.mdoutput_chunk0042.meta.json observations for glossary feedbackBefore launching subagents, scripts/run_state.py plan <temp_dir> decides which chunks need translation, which existing outputs only need state recording, and which are unchanged. Use --retranslate-untracked only when adopting an old temp dir whose existing outputs should be forced through the current glossary. If a run is interrupted, re-running skips chunks that already have valid output files and current state. Failed chunks are retried once automatically.
python3 scripts/merge_and_build.py --temp-dir book_temp --title "《translated title》"
Optional output flags:
python3 scripts/merge_and_build.py --temp-dir book_temp --title "《translated title》" --cover cover.jpg --export-name "translated-title"
--cover passes an explicit image to the EPUB Calibre step. --export-name creates alias copies such as translated-title.epub while preserving the canonical book.* pipeline artifacts.
Before merging, the script validates:
Then: merge → Pandoc HTML → inject TOC → Calibre generates DOCX, EPUB, PDF.
Note: {book_name}_temp/ is a working directory for a single translation run. If you change the title, author, output language, template, or image assets, either use a fresh temp directory or delete the existing final artifacts (output.md, book*.html, book.docx, book.epub, book.pdf) before re-running.
| File | Purpose |
|---|---|
SKILL.md | Agent skill definition — orchestrates the full pipeline |
scripts/convert.py | PDF/DOCX/EPUB → Markdown chunks via Calibre HTMLZ |
scripts/manifest.py | Chunk manifest: SHA-256 tracking and merge validation |
scripts/glossary.py | Glossary management: per-chunk term tables for consistent terminology |
scripts/chunk_context.py | Read-only previous/next chunk excerpts for sub-agent prompts |
scripts/meta.py | Per-chunk sub-agent observation file schema (output_chunkNNNN.meta.json) |
scripts/merge_meta.py | Batch-boundary merge: sub-agent observations → canonical glossary |
scripts/run_state.py | Selective re-translation planner and run_state.json recorder |
scripts/merge_and_build.py | Merge chunks → HTML → DOCX/EPUB/PDF |
scripts/calibre_html_publish.py | Calibre wrapper for format conversion |
FAQ
translate-book is a Claude Code plugin with 1 hand-picked skill for content work, indexed on Flowy. Install it with the command on its page. It includes translate-book. Its skills do not fire on their own yet. Request auto-invocation to have Flowy route them as you prompt. Free and open source.
Is this plugin yours?
Claim it with GitHubSubmit a pluginPromote it