translate-book
Skill1 starsChanged 36 days agoMITView on GitHub
Translate an EPUB or PDF technical book into another language while preserving its structure — chapters, code blocks, links, figures, tables, code callouts — and rebuild a valid EPUB. Use when the user asks to 翻译整本书 / 翻译这本书 / translate a book / translate an EPUB or PDF book / 把 PDF 转成中文 epub / 转成 epub 格式, or hands over an .epub or .pdf book file with translation intent. Not for single articles or web pages — use baoyu-translate for those.
6 other projects use a version of this.
Adopted by
Most recently taken up by
- JayMeDotDot/jmdd-agent-skillstheir own version, first seen Nov 1, 2026
- skitniknikita/book-translation-agenttheir own version, first seen Oct 17, 2026
- kcy4334-lgtm/translate-book-arxivtheir own version, first seen Oct 9, 2026
- DDChen666/translate-booktheir own version, first seen Oct 9, 2026
- deusyu/translate-booktheir own version, first seen Sep 5, 2026
- trananhtung/translate-booktheir own version, first seen Jun 29, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- deusyu/translate-book★ 2.4ksame name
- kcy4334-lgtm/translate-book-arxiv★ 38same name
- skitniknikita/book-translation-agent★ 4same name
- DDChen666/translate-book★ 2same name
- trananhtung/translate-book★ 2same name
- JayMeDotDot/jmdd-agent-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repositoryOne other file it gives its agents.
- skills/translate-book/AGENTS.mdAGENTS.md
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 82
A worker's self-report is not a merge gate: Only validate-batches / complete decide.
- Very specific: line 104
Use AGENTS.md as the prompt template.
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Translate a Book
Structure-preserving book translation. The governing rule:
Never regenerate a book from plain text. Parse it into translatable units, replace only the text, write it back into the original structure, then package.
Regenerating loses styles, anchors, figure placement, and code formatting. A book has thousands of structural dependencies; markdown round-trips break them silently.
Pipeline
- Extract —
units.py extractturns each chapter into units. Point it at the directory holding the chapter XHTML (usuallyOEBPS/Text/), and at the directory that holds only those files — the tree root will find nothing.- Inline markup →
⟧n⟦…⟧/n⟦tokens (links, emphasis). Inner text is translated. - Code/images/MathML →
⟨n⟩atoms. Element preserved verbatim, never translated. <pre>/<code>subtrees are skipped entirely.
- Inline markup →
- Self-test —
units.py write --identity --strict, thendiff -ragainst the source. Text must match except for intentional normalizations, and the command must exit 0. Do this before any translation. It catches every index-alignment bug in minutes. - Batch —
units.py batchinto ~1600-word chunks. It writes_plan.jsoncarrying a hash of every planned unit; the hash is what later detects outputs produced against an older plan. - Glossary and register —
units.py glossary <units>seedsglossary.jsonfrom the source (capitalized terms, acronyms,a.bsymbols). Fill in the empty values, then write the register note once. Both travel with every dispatch; without them parallel batches invent competing terms. - Dispatch —
units.py claim <batches> <done> --worker IDprints the next unclaimed batch files. A worker writes into its own run directory, never intodone. - Promote —
units.py complete <batches> <run_dir> <done> --units-dir <units>validates the run directory and atomically copies only the files that pass. A worker's own "done" report is not evidence. - Merge —
units.py merge <units> <done> <trans> --batches-dir <batches>refuses an incomplete plan by default; use--allow-incompleteonly for an explicitly approved partial delivery. - Write back —
units.py write. Validates tokens/atoms per unit and refuses to write a unit that fails. - Package —
epub_build.py. - Verify —
epub_verify.py, diffing element counts against the source. - Sample —
units.py sample <units> <trans> --out sample.jsondraws a fixed review sample per chapter (long prose, headings, cross-references, units with tokens or atoms) and flags empty, untranslated, and marker-damaged units.
Re-run steps 8–11 freely. Re-running 1 is expensive once translations exist — see Reusing translations in REFERENCE.md.
Interrupted runs
units.py status <batches> <done> --units-dir <units> is the only source of
truth: planned/complete/missing/invalid/claimed/stale. Recover in this order:
missing— re-claim those batches and re-dispatch:units.py claim ...invalid— the file exists but fails validation; re-dispatch it, do not edit it.claimedbut the worker died —units.py claim --worker ID --release <dead worker>.stale— the plan changed since those outputs were promoted;rekeyfirst, then re-dispatch the residue.
Non-negotiables
- The writer must not mutate the source. Copy to a staging dir, overlay translations there, zip the staging dir. A builder that writes into the source turns the next extract into garbage (it parses the translated output as English).
- Extractor and writer share one traversal function. Enumerate elements independently and any disagreement silently shifts every index.
- Materialize the element list before mutating the tree. lxml iterators skip elements when children change mid-iteration — you get one paragraph per chapter.
- Code is never translated. Prose wrapped around inline code is.
- MathML is never translated. Inline equations are atoms; their surrounding prose remains a unit.
- Validate before writing, never after. Failed units keep their source text. Batch validation and merge must stop before a missing translation can become a finished EPUB.
- A worker's self-report is not a merge gate. Only
validate-batches/completedecide. Sessions that trusted the report shipped books with whole batches still in English. - One worker, one directory. Workers write to private run directories;
promotion is a separate, atomic step. Two workers sharing
doneoverwrite each other's half-finished files.
Knowing when the source is lying
Published books contain production defects: double-encoded entities, a stray styled character mid-word, duplicated margin labels. Translate the intent and record the exception — don't reproduce the defect, and don't silently drop it. See the failure catalogue in REFERENCE.md.
Reading order is the hard part (PDF only)
EPUB sources carry structure. PDFs do not — you rebuild it from glyph coordinates and font names, and the layout rules are per-book: sample pages first, build a font→role table, then extract. Recipe and pitfalls: REFERENCE.md.
Delegating translation
Use AGENTS.md as the prompt template. Give each worker a private
run directory, take its file list from units.py claim, and promote it with
units.py complete. The token/atom rules matter more than style guidance — a
subagent that mangles a token corrupts the book.
Two subagents at a time is the usual ceiling. Group batches by chapter so
terminology stays consistent within a run, and hand every worker the same
glossary.json and register note — terminology cannot be re-derived per batch.
Scripts
| Script | Purpose |
scripts/units.py | extract / write / batch / glossary / claim / validate-batches / complete / status / merge / sample / rekey |
scripts/pdf_layout.py | PDF → structured document (coordinates + fonts) |
scripts/epub_build.py | stage + package a valid EPUB |
scripts/epub_verify.py | integrity, coverage, structure diff |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

