Skip to content

Translate the book before download, Russian first (1.5.0) - #4

Merged
pruffit merged 2 commits into
mainfrom
feat/translate
Oct 16, 2026
Merged

pruffit merged 2 commits into
mainfrom
feat/translate

Conversation

@pruffit

@pruffit pruffit commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Optional translation of the whole book before download — Russian first, a dozen other languages — so a work that is not in your language arrives in it.

What changes

  • Where it runs: after the chapters are fetched and before the file is written, so EPUB, MOBI, FB2 and TXT all get it.
  • What gets translated: chapter titles, text and end notes, the book title and summary. language becomes the target, and the filename uses the translated title.
  • Panel: a Translate row, off by default, with thirteen languages named in their own language; the choice is remembered in chrome.storage.sync. When translation is on, a line says chapter text goes to Google Translate. With it off, nothing is sent beyond the site itself.
  • Engine: Google's translate_a/t with format=html, which keeps inline markup, behind a small Translator interface so other engines can be added.
    • Requests are batched under a character budget, paced, retried on 429/5xx (honouring Retry-After), and abortable.
    • Whatever comes back is sanitised again.
  • Already in the target language? Decided by the language Google reports for the first chapter body with enough text — not by the ru/en guess and not by author notes. A Ukrainian work with Russian selected is translated; a Russian one costs a chapter's worth of requests and is returned as is, with a note.
  • Partial failure: a chapter Google keeps refusing stays in the original and the book is still built, with a note saying how many. Only when every chapter fails does the build stop.
  • AO3: with translation on, the site's ready-made file is skipped, since the translation has to happen here.
  • Version: 1.5.0.

Checked

  • npm run check: typecheck, build, and 26 + 19 + 35 tests. The new tests cover markup preservation, batching, retry, abort, the language vote, partial failure, and an EPUB built from a translated book.
  • Live in Chromium with the unpacked extension:
    • Royal Road, 4 chapters, Русский: 11 requests. The EPUB has Russian text, dc:language ru, em/strong/br counts identical to the original, and every part parses.
    • Translation off: zero requests to Google.
    • ficbook, Русский: 4 requests, skipped as already Russian, original EPUB.
  • Not checked live:
    • AO3 (Cloudflare challenge for automation);
    • a real 429 from Google (fake-fetch tests only);
    • the MOBI, FB2 and TXT output of a translated book.

🤖 Generated with Claude Code

pruffit and others added 2 commits October 16, 2026 15:41
The main user downloads works that are not in Russian and wants to read them in
Russian. Translation runs after the chapters are fetched and before the file is
written, so every format gets it: chapter titles, text and end notes, the book title
and summary; the language becomes the target.

The panel gets a Translate row (off by default, thirteen languages, remembered in
storage) and, when on, a line saying chapter text goes to Google Translate; with it
off nothing is sent beyond the site itself. The engine is Google's translate_a/t with
format=html, which keeps inline markup, behind a small Translator interface. Requests
are batched under a character budget, paced, retried on 429/5xx with Retry-After, and
abortable; whatever comes back is sanitised again.

Whether the book is already in the target language is decided by the language Google
reports for the first chapter body with enough text, not by the ru/en guess, so a
Ukrainian work with Russian selected is translated. A chapter Google keeps refusing
stays in the original and the book is still built, with a note saying how many.

Closes #3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pruffit
pruffit merged commit 67a564a into main Oct 16, 2026
1 check passed
@pruffit
pruffit deleted the feat/translate branch October 16, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant