feat(translate): map a public-domain translation onto the game's speeches

Add the translate {fetch,build,status} stage: parse a Project Gutenberg
ebook into speeches and directions, align them with the game's speeches by
speaker sequence, group split or merged speeches, and accept verbatim
overrides. Output: data/translations/<code>.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-20 13:38:28 +02:00
1 parent 70a0ad577b
commit 33c8b32b69
9 files changed
+1093 -2

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ redone unless their input changes.
| Annotation | `annotate run/status/prompt/merge` ([details](annotation.md)) | `annotate.py` |
| Assets | `assets prompt/import/process/check/status/placeholders/sheet/migrate` | `assets.py` |
| Voice (optional) | `voice fetch/asr/build/cut` ([details](voice.md)) | `voice.py`, `voice_align.py` |
| Translations (optional) | `translate fetch/build/status` ([details](translations.md)) | `translate.py`, `translate_align.py`, `renpy_tl.py` |
| Ren'Py | `renpy [--from-parsed] [--with-test] [--out DIR]` | `renpy_gen.py` |
`--work DIR` (before the subcommand) selects the work root; default is the current directory.
+108
View File
@@ -0,0 +1,108 @@
# Translations
A work can be played in other languages besides its own, from a **published public-domain
translation** of the same text. vnpipe never translates or rewrites the play: every line shown
in another language is copied verbatim from that translation (a Project Gutenberg ebook).
Only the game's own interface strings (menu labels, scene subtitles, credits) are written in
`work.toml` per language.
```
translation ebook ──translate fetch──▶ data/raw/<file>.txt (gitignored)
──translate build──▶ data/translations/<code>.json (committed)
──renpy──▶ game/tl/<language>/script.rpy, strings.rpy
game/languages.rpy (the choice: Preferences, first launch)
```
## Mapping (`translate build`)
The ebook (Gutenberg header, footer and licence removed) is cut at each scene's heading and
parsed into **units**: speeches (split at stage directions) and stage directions. The game
side has the same units: each direction line and each run of lines with the same speaker and
speech. The two sequences are aligned (dynamic programming): a speech pairs only with a speech
of the same speaker (two ids of `ensembles` may pair, at a penalty), a direction with a
direction; similar sizes score higher.
Translators split and merge speeches differently, so the units are **grouped**: source units
left between two pairs are shown with the first unpaired game unit of the stretch (else with
the previous pair). Every source unit is shown exactly once, in the translation's order, each
with its own speaker. A game unit with no text of its own shows nothing in that language.
Parsing rules worth knowing (`translate_align.parse_units`):
- an upper-case line followed by a blank line is a speaker label, mapped by `speakers`; an
indented one only for a known speaker (a chorus inside a song);
- `(...)` blocks, `[Exit` lines (also at the end of a verse line) and italic paragraphs are
directions; a note under a label becomes `LABEL (note)`; a parenthesis inside a stanza
ending in punctuation (`(These elements),—`) is verse;
- before the first speech, place and cast lines form one **setting** unit, used only where an
override puts it; footnote numbers at line ends and illustration markers are dropped.
`translate status` prints coverage per scene (worst first): `paired` and `carry` units show
their own text, `grouped` ones show nothing; `suspects` are groups whose size ratio is far from
the scene's. `translate status --scene ID` prints the alignment side by side. Fix a wrong
pairing with an override that quotes the translation verbatim (see below); the build fails if
the quote does not start exactly one unit. A scene is `complete` when its first unit has text.
## Ren'Py output
Every say statement carries an explicit `id` (its first line id), and each translation writes
`translate <language> <id>:` for all of them: the first box of a game unit with text shows the
translated units (split into boxes like the original: stanzas, at most 4 lines in ADV and 8 in
NVL, long prose paragraphs cut at sentence ends), every other box is `pass`. The voice clips
are shared: a clip that starts in the group starts on the first translated box of the same
speaker and `voice sustain` carries it over that speaker's next boxes and directions.
Names, title cards, the scene list, About and the art-style labels go to `translate <language>
strings:`; equal original strings that translate differently get `{#scene}` tags. The credits
are a list per language (`vn_credits_tl`). `vnpipe renpy` fails if the JSON is missing or was
built from another `data/annotated.json`.
The language choice (`game/languages.rpy`): the work's own language is the default; the player
picks another in Preferences ("Language") or in the first-launch picker. The choice is stored
in `persistent.vn_language` and copied to `config.language`, so a stale preference never
switches the language and loading a save keeps it. `RENPY_LANGUAGE=<language>` forces one
(e.g. for the playthrough test).
## Configuration
```toml
[translations.en]
language = "english" # Ren'Py language name
label = "English" # shown in the language choice
text_url = "https://www.gutenberg.org/cache/epub/NNN/pgNNN.txt"
text_file = "data/raw/pgNNN.txt" # cache (gitignored)
gutenberg_id = NNN # credited as the source
title = "Faust" # [work] fields in this language
subtitle = "First Part"
translator = "..."
end_text = "To be continued…"
voice_credits = ["..."] # [voice].credits in this language
ignore_lines = ["..."] # exact lines of the ebook that are not play text
ensembles = ["chorus"] # default: [voice].ensembles
[translations.en.speakers] # speaker label as printed -> cast id
"MEPHISTOPHELES" = "mephisto"
[translations.en.scene_speakers.<scene id>] # per-scene overrides of `speakers`
[translations.en.direction_labels] # labels printed like a speaker but read as a direction;
"FAUST AND WAGNER" = "" # the text after is spoken by this cast id ("" = none)
[translations.en.names] # cast id -> name (every named cast member)
mephisto = "Mephistopheles"
[translations.en.strings] # other strings of the work (art-style labels)
"Pictórico" = "Painterly"
[[translations.en.sections]] # one per scene, in play order
scene = "noche"
heading = "NIGHT" # heading line in the ebook, searched in order
title = "NIGHT" # optional: shown heading (default: `heading`)
subtitle = "Faust’s study · Night" # card subtitle
# default_speaker = "poet_voice" # a section without speaker labels is one speech
[[translations.en.overrides]] # forced pair: game unit (first line id) <-> source unit
scene = "dia_nebuloso"
game = "dia_nebuloso_0001"
source = "A FIELD" # verbatim start of the source unit (markup removed)
```
+8 -1
View File
@@ -7,7 +7,7 @@ A work is a directory containing `work.toml`, plus the folders the pipeline fill
| Table | Keys |
|---|---|
| `[work]` | `id`, `title`, `subtitle`, `author`, `translator`, `language` (`es`/`en`: About, menu and credits texts), `lyric_voice` (cast id for verse nobody speaks; default `poet_voice`), `end_text`, `menu_bg` (legacy alias of `[ui].main_menu_bg`). |
| `[ui]` | `main_menu_bg` (background asset id of the main menu and, darker, the game menu; default: `[work].menu_bg`, else the first staged `bg`); `language` (Ren'Py language name, e.g. `spanish`, forced with `config.language` so an old persistent preference cannot switch the menus back to English; vnpipe ships `renpy_templates/tl/<language>/` (Ren'Py's common strings and every template screen string; only `spanish` so far) and copies `<work>/tl/<language>/*.rpy` on top, a work file replacing a shipped file with the same name). |
| `[ui]` | `main_menu_bg` (background asset id of the main menu and, darker, the game menu; default: `[work].menu_bg`, else the first staged `bg`); `language` (Ren'Py language name of the work's own language, e.g. `spanish`; it is the default and `config.language` follows only the player's explicit choice, so an old persistent preference cannot switch the menus back to English; `language_label` (its name in the language choice, default from `[work].language`); vnpipe ships `renpy_templates/tl/<language>/` (Ren'Py's common strings and every template screen string; only `spanish` so far) and copies `<work>/tl/<language>/*.rpy` on top, a work file replacing a shipped file with the same name). |
| `[source]` | `gutenberg_id`, `url`, `raw_file` (cache path, relative to the work root, gitignored). |
| `[scope]` | `start_marker`, `end_marker` (whole stripped lines), `end_occurrence` (1-based, searched after the start; the end marker itself is excluded). |
| `[speakers]` | Speaker heading as printed (upper case, without its italic note) → cast id. Several headings may share one id (anonymous crowd speakers). A key with punctuation or markup (`"CORO, TUTTI"`) is matched against the whole printed line first. An unknown speaker is a parse error. |
@@ -127,3 +127,10 @@ heading = "Straße (I)" # heading line in the source text, s
Voice data lives in the work: `voice/asr/NN.json` (committed ASR cache), `voice/map.json`,
`voice/report/<scene>.txt`, `voice/clips/*.ogg`. `vnpipe renpy` copies the clips to
`game/voice/` and credits them when `[voice].credits` is set.
### Translations
Optional `[translations.<code>]` tables: other languages from a published translation of the
text (verbatim, never machine-translated). Configuration, mapping rules and the Ren'Py output
are in [translations.md](translations.md); the mapping is committed as
`data/translations/<code>.json`.