Bilingual EPUB reader

Builds a bilingual EPUB that keeps the original text intact and places the translation under each paragraph.

#EPUB#bilingual reader#verbatim check#parallel agents#hover dictionary
Bilingual EPUB builder (EN-ZH, JA-ZH)

WorkflowBilingual EPUB builder (EN-ZH, JA-ZH)

Reading & i18n Local MacBook

A workflow that turns an English EPUB or a Japanese book into a single HTML file with Chinese literal and free translations beneath the original and a dictionary on hover. Scripts produce the original text deterministically; the model writes only the translations.

Challenge

  • A translation alone hides the original wording; the original alone means looking up word after word
  • When AI translates a whole book in one go, dropped paragraphs or silent summarising go unnoticed

Approach

  • First convert the EPUB into a reading edition and verify by machine that its text matches the EPUB character for character
  • Split the original into units with IDs and let parallel agents write only the translations. Separate agents sample for errors, and a judge decides what to apply

Outcome

  • One HTML file shows literal and free translations under the original, with meanings on hover
  • Scripts own the original text, so however the translation varies the original never breaks; progress is tracked as one sub-task per chapter

This is the workflow the author uses to read English and Japanese books alongside Chinese. English EPUBs go through a reading edition and then an English–Chinese edition; fixed-layout Japanese books are read from page images into a Japanese–Chinese edition.

On both routes scripts produce the original text and the model writes only translations. Book content is copyrighted, so it stays for personal reading; only the procedure and the scripts are shared.

The full workflow

TaskWhoInputsOutputs
1. Build copyBuilderbuild.pySource EPUBReading copy
2. Verbatim checkVerifierverify.pyReading copyVerbatim check
3. Split unitsExtractor + Sharderextract_book.py + shard.pyVerbatim checkSource units
4. TranslateTranslators + Workflow script + Mergersubagents + workflow .js + merge.pySource units, Refers to Rules+glossaryTranslations
5. Sample reviewReviewers + Sampler + Workflow scriptsubagents + sample_review.py + workflow .jsTranslationsReview notes
6. Judge fixesJudge + Collector + Workflow scriptsubagent + build_fixes.py + workflow .jsReview notesFix list
7. Apply fixesApplierapply_fixes.pyFix listRevised text
8. DictionaryDict builderbuild_dict.pySource unitsDictionary
9. AssembleAssemblerassemble.pyRevised text, DictionaryBilingual HTML
Bilingual EPUB builder (EN-ZH, JA-ZH)

9 steps · 3 roles · 2 loops · since 2026-08-24 · 1,339 units in one book · 77 fixes over 2 review rounds

Scripts turn the EPUB into a reading copy without changing a character, agents write only translations, other agents sample for errors, a judge decides what to apply, and the bilingual edition is assembled.

  • Scripts produce the original text (1–3, 8–9); agents write translations (4). However translations vary, the original cannot break
  • Translation (4) and error-hunting (5) run in separate contexts; the judge (6) may also reject findings
  • Two loops: a mismatch sends you back to the conversion rules; many fixes trigger another sample round with a new seed
  • Book content is copyrighted and stays for personal reading; only the procedure and scripts are shared

Project folders involved (3)

This workflow does not live in one folder: it runs across projects.

(private) reading folder
A private reading folder: the conversion, verification and bilingual scripts and the translation spec; book content stays out of the repository
reading-kit plugin
The author's plugin: it holds the reading-copy skill and the English and Japanese bilingual skills
site-bilingual plugin
The injection engine and dictionary builder come from here
Build copy

Step 1 · Builder

Build copybuild.py

The EPUB becomes a single-file reading copy with a table of contents.

  • Each book gets one entry in the register: category, title, language and conversion profile
  • Print-only clutter is hidden by default and the contents sit in a sidebar
  • Quirks of a particular book are fixed in its profile; the generated HTML is never edited by hand
InputsSource EPUB
OutputsReading copy
Verbatim check

Step 2 · Verifier

Verbatim checkverify.py

A script checks that the reading copy matches the EPUB character for character.

  • It compares the full text and stops at the first divergence
  • Nothing moves on until they match
  • Fixes go into the conversion rules; output is never patched by hand to match

Common misconceptionText can look right yet drop characters after a hidden node; the verbatim check catches that

InputsReading copy
OutputsVerbatim check
Split units

Step 3 · Extractor + Sharder

Split unitsextract_book.py

The text is split into units with IDs and cut into shards for translation.

  • Pages with nothing to translate, such as the index, are skipped
  • One technical book came to 1,339 units in 34 shards
  • Book-specific rules and a glossary are added to the translation spec (code lines are copied as-is, for example)
InputsVerbatim check
OutputsSource units
Translate

Step 4 · Translators + Workflow script + Merger

Translateone per shard

One agent per shard writes only the literal and free translations.

  • Translations are keyed by unit ID, so the original is never touched
  • Units whose translation equals the original, such as code lines, are not inserted, so nothing prints twice
  • An earlier art book was translated in full: 3,439 of 3,439 units

Claude CodeA workflow script starts one subagent per shard and runs them in parallel

InputsSource units
OutputsTranslations
Refers toRules+glossary
Sample review

Step 5 · Reviewers + Sampler + Workflow script

Sample reviewone per packet

Agents in a separate context look only for errors in sampled units.

  • Four things only: omissions, additions, mistranslations and inconsistent terms; style preferences are not reported
  • A fixed seed makes the sample reproducible, and repeated draws never overlap until everything is covered
  • Even with zero issues a result file is kept as proof of review
InputsTranslations
OutputsReview notes
Judge fixes

Step 6 · Judge + Collector + Workflow script

Judge fixesveto allowed

A judge agent rules on each finding, accept or reject.

  • Findings from all packets are merged into one candidate list
  • The judge has a veto and writes only what it accepts
  • The judge never edits the translations themselves
InputsReview notes
OutputsFix list
Apply fixes

Step 7 · Applier

Apply fixesapply_fixes.py

Accepted fixes are written back, after a dry run and a backup.

  • Before writing, each fix's "before" text must match the current translation, or it is skipped
  • Round 1 checked 240 units: 22 findings accepted, 36 places fixed; round 2 used a new seed on 360 units: 26 accepted, 41 places
  • If many places changed, another sample round with a new seed follows
InputsFix list
OutputsRevised text
Dictionary

Step 8 · Dict builder

Dictionarybuild_dict.py

A dictionary limited to the book's words is built for hover lookup.

  • Words are collected with code lines left out
  • The full dictionary stays on this machine and never enters the repository
  • Where useful, a "usage in this book" sense is added
InputsSource units
OutputsDictionary
Assemble

Step 9 · Assembler

Assembleassemble.py

Translations and the dictionary are injected into the reading copy as one bilingual file.

  • Injection uses the same engine as the site mirror, and the reading copy's text is not changed by a character
  • Literal and free translations sit under each English block, with meanings on hover
  • Progress is tracked as one task per chapter
InputsRevised text, Dictionary
OutputsBilingual HTML

Loops and rework

  • Verbatim mismatch → step 1: Fix the conversion rules (the book's profile) and rebuild; never patch the HTML
  • Many fixes applied → step 5: For one technical book a second round really ran with a new seed and 26 more findings were accepted

Key points

Never change a character of the original. The reading edition is compared with the EPUB in full, character by character, and nothing moves on until they match. Fixes go into the conversion rules; generated HTML is never edited by hand.

Let the model write only translations. The original is split into units with IDs, and translations are inserted by ID. Units whose translation equals the original, such as code lines, are not inserted, so nothing is printed twice.

Keep translating and error-hunting apart. Sampling reviewers run in a different context from the translators and report only omissions, additions, mistranslations and inconsistent terms, never style preferences. The judge that applies fixes may also reject them.