|
|
2 kuukautta sitten | |
|---|---|---|
| .. | ||
| cases | 2 kuukautta sitten | |
| README.md | 2 kuukautta sitten | |
| skeleton.html | 2 kuukautta sitten | |
| terminology.template.json | 2 kuukautta sitten | |
Distilled from reference examples m09 (Email -> Chinese-translated PDF, layout preserved). HTML parse -> terminology freeze -> translate -> Chromium print.
HTML parse -> terminology freeze -> translate -> Chromium print -> PDF
.eml / .html / .pdf text layer) into structured paragraphs + image
references (preserve byte-level URL / data-uri / cid: references).terminology.json (after the first 3 iterations the file
is read-only for every later round).Why not the token pipeline: the source already has a rich layout (tables, figures, nested lists). A token rebuild loses both spatial fidelity and image byte tracking. HTML -> HTML -> PDF is the natural "layout-preserving" path.
<img src="cid:..."> or <img src="data:image/..."> exactly as-is;
max-width: 88% to prevent overflow.page-break-inside: avoid + max-height: 400pt to prevent orphans.See skeleton.html (HTML template, ~150 lines) +
terminology.template.json (terminology schema).
Quick start:
# 1. Extract source
python3 -c "import html_parse; html_parse.extract('source.eml', out='/tmp/extracted/')"
# 2. Build terminology.json (settle within first 3 iterations, then freeze)
cp templates/translate-preserve-layout/terminology.template.json /tmp/extracted/terminology.json
# Fill in your domain terms.
# 3. Translate every paragraph using the frozen terminology.
python3 translate.py --in /tmp/extracted/ --terminology /tmp/extracted/terminology.json --out /tmp/translated/
# 4. Render HTML (skeleton + translated data).
cp templates/translate-preserve-layout/skeleton.html /tmp/translated/page.html
# Fill in placeholders.
# 5. Chromium print.
node packages/local-runtime/assets/skills/pdf/scripts/render_html.cjs /tmp/translated/page.html /tmp/translated/out.pdf
# 6. Verify image count.
src_imgs=$(pdfimages -list source.pdf | tail -n +3 | wc -l)
out_imgs=$(pdfimages -list /tmp/translated/out.pdf | tail -n +3 | wc -l)
[ "$src_imgs" = "$out_imgs" ] || echo "Warning: image count drift: src=$src_imgs out=$out_imgs"
For a full production trace of a rich Goldman Sachs research EML translated to Chinese while preserving cid chart images, links, A4 geometry, and CJK typography, load:
Use the case when the source EML has text/html plus inline cid: images. It contains the
optimized reusable translation prompt, Doctype-safe segment extraction, and verification gates; do
not duplicate those details here.
terminology.json after
the first 3 iterations; treat it as read-only afterwards.pdfimages -list before and after rendering; source must equal output.cid: references and let Playwright render natively.pdftotext.is_translatable: true in the schema.max-width constraints.page-break-inside: avoid on <figure>.category: proper_noun, note: preserve English / no invented translations.preserve in terminology.json and grep the rendered PDF to verify.Required placeholders:
paragraphs_translated[] (categorised by type).images[] (with original cid: / data-uri).terminology.json (per-domain glossary; frozen after 3 iterations).Optional / swappable:
lang="" and the font cascade.Structural invariants:
@page A4 + 11-14 mm margins (match source).max-width: 88% on <img.exhibit>.page-break-inside: avoid on <figure>.line-height: 1.6 minimum.proper_noun (preserve English; do not invent translations).Domain swappable: finance (baseline) / legal / technical / medical / political — each domain
produces an independent terminology.json.
Diversify every run. REFORMAT is the one route where you should not invent new visuals — the
whole point is layout fidelity to the source. But per-domain terminology.json, target language,
and CJK font cascade still need to be re-picked per task: a finance translation for a HK firm and a
medical translation for a JP hospital should not share the same glossary or font stack. Always start
a fresh terminology.json from the source's domain.