Skip to content

Machine translations of the README, quickstart and use-case pages stay current through a workflow - #600

Merged
zlareb1 merged 12 commits into
mainfrom
ci/i18n-translations
Nov 13, 2026
Merged

zlareb1 merged 12 commits into
mainfrom
ci/i18n-translations

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Documentation (changelog entry is not required)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

...

Why

The README had one hand-written translation (README.zh-CN.md) that drifted whenever the English page changed and needed a hand edit in the same PR. This replaces it with machine translations of a fixed page set (the README, the quickstart and the nine use-case pages) into Simplified Chinese, Japanese, Korean, Brazilian Portuguese, Spanish and Russian, kept current by a workflow instead of by every PR author.

  • scripts/i18n/translate.py sends each page to the Messages API one ## section at a time, over the standard library (no new dependency), several pages at once. A section's translation is kept only when its fenced code blocks (in order), inline code spans, link targets, URLs (autolinks and bare ones included), heading anchors and numbers match the English section, and no heading or link text within the set comes back in English (names excepted; a link to an English-only page may keep that page's title). Otherwise the call is retried once with the differences named, then the run fails.
  • Relative links in the prose (Markdown links, images, href/src, reference definitions; never inside code) are rewritten before translation: a page in the set links to its translation, anything else to the English file on GitHub (images to raw/). Every heading gets an <a id> with its English anchor, computed the way tests/unit/markdown_links.py checks the English links, so #anchor links keep working.
  • A per-language line in the prompt fixes punctuation, line joining for Chinese and Japanese, and a few terms, so sections translated apart read alike.
  • Each file starts with a stamp (source=, the git blob of the English page, model=) and a two-line banner, in the target language and in English, saying the English page is authoritative. translate.py check reports a page that is missing or whose stamp or banner differs (another English blob, model or banner), a translation of a page no longer in SOURCES, a relative link or #anchor that points at nothing, a heading or in-set link text left in English, and a README whose language line differs from the generated one. A change to the prompt text changes no stamp: update --all (the workflow's all input) translates again.
  • The README's language line sits between <!-- languages --> markers and is generated, not translated: each README lists all seven languages and links to the other six. check compares every README's line with the generated one, and update rewrites a line that differs without translating it; a README without the markers stops update. Adding a language changes the English README's line, so its blob, and every README is translated again (a --lang run translates only the languages it names; check reports the rest until they are).
  • .github/workflows/i18n.yml runs from main only: on a push that changes the README or anything under docs/ (check exits clean when nothing is stale), and on a manual run with all and languages inputs. It translates, runs check --skip-stale (links, anchors, labels and orphans across i18n/) before anything is pushed, and opens or updates one PR from i18n/update, title and body. When some pages fail, the pages that passed still land in that PR and the job then fails (an anchor into or out of a page that is still stale is not checked until that page is translated), so one difficult section does not throw away the rest; once that PR is merged, a later docs push translates only what changed since. Each run starts from main, so while the translations PR is still open a later docs push translates the pages stale on main again (bounded by the cap); merging it promptly keeps runs small. The steps run under bash -o pipefail.
  • Cost: the run estimates its spend before the first call (system prompt and anchors included; a full run estimates $3.81, printed by python -c "from scripts.i18n import translate as t; print(t.estimate_usd(t.DEFAULT_MODEL, sum(t.request_chars(s, l) for s in t.SOURCES for l in t.LANGUAGES)))"; measured runs cost from about 20% under the estimate to 6% over it) and refuses a run over LOOM_I18N_MAX_USD (5). Every call checks the reported spend against the cap first, so the spend passes it by at most the calls in flight, one per worker. The first page that fails stops every worker before its next call. A timed-out request is not retried (it may have been billed), and an unpriced model is refused.
  • Freshness is not a PR gate: an English edit must not fail the PR that makes it. tests/unit/test_i18n.py checks the generator and the committed files (all 66 present, none orphaned, stamped, bannered, links and anchors resolving, labels translated).

Scope and risk

New i18n/ (66 generated files), scripts/i18n/, the workflow, and the README's language line. README.zh-CN.md and tests/unit/test_readme_translation.py are removed; i18n/zh-CN/README.md replaces them. i18n/ is in .prettierignore (generated, never formatted by hand) and in the public-copy scan, and test_install_script.py skips it when it collects documented install commands (those blocks are byte copies of the English ones). Four English sentences in three pages change, because translations read "the right file among its three" as a choice among three given candidates and put the 21% cost cut on the wrong run: docs/use-cases/code-intelligence.md, the README's results note and two lines of docs/benchmarks/results.md (the summary table and the conceptual-questions protocol) now say the agent is asked to end its answer with up to three files (as bench/agent_localization_ab.py prompts it), and code-intelligence.md states the cost cut for the runs with Loom.

A PR that adds a page to SOURCES commits its translations (update with an ANTHROPIC_API_KEY); the docs rule says so.

Model: claude-sonnet-5-5, effort low (LOOM_I18N_MODEL picks another priced model). A full run of all 66 pages measured $3.17 (332,930 input and 250,583 output tokens). The committed pages come from that run's prompt revision for four languages and a later one for Chinese and Japanese: 22 pages in 151 s for $1.22, and 20 pages in 162 s for $1.73, six pages at a time; two Japanese pages were then regenerated after a review read a reversed claim in one ($0.31), the README, the quickstart and the code-intelligence page in every language after the rebase onto main ($2.73 against an estimate of $2.57, 218 s), and the README and code-intelligence page again after the English rewording ($0.86; a first attempt stopped when the Japanese README kept a link text in English, which exercised the stop-and-keep-what-passed path). A run after an edit to one page costs a few cents per language.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: add the repository secret ANTHROPIC_API_KEY, and allow GitHub Actions to create pull requests (Settings → Actions → General → Workflow permissions). A PR opened with the workflow token starts no other workflow; close and reopen it to run CI. Until the secret exists the workflow fails when a translation is stale, and the committed translations stay as they are.
  • Rollback: reverting removes i18n/ and the workflow and restores README.zh-CN.md.

Tests

  • tests/unit/test_i18n.py: 54 tests, passing (the worker-pool test passed three runs in a row).
  • python -m scripts.i18n.translate check: exit 0 on this head.
  • make format-check, make lint, make typecheck: pass.
  • test_i18n.py, test_doc_links.py, test_public_copy.py, test_agent_instructions.py, test_install_script.py: 693 passed on this head (rebased onto main after A burst of package-manager connections no longer kills the sandbox's egress relay #579).
  • An earlier head ran the full tests/unit on 4 workers: 34457 passed; test_deeply_nested_hidden_html_parses_in_bounded_time fails on this host under parallel load and is untouched by this change.
  • Not run: the workflow itself, including its partial-run path (the ok output, the PR step, the final failing step). It runs only from main with the secret; the first run after merge shows it.
  • Read by hand: the 96.4% sentence in all six languages, the Chinese, Japanese, Korean and Russian README and quickstart openings and headings, the language line, the anchors and the badge and image links.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked the verifier against a section whose code span wraps a line (an earlier run stopped on it), the untranslated-label check against every committed page before and after regeneration, the link rewriting from every source directory, and the generated pages listed above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the ci/i18n-translations branch 2 times, most recently from e1966c4 to 4563d08 Compare November 13, 2026 06:45
zlareb1 and others added 6 commits November 13, 2026 06:52
…y current through a workflow

i18n/<lang>/ holds generated translations into six languages, each stamped
with the English page's blob and verified to keep code, links, anchors and
numbers. scripts/i18n/translate.py checks and refreshes them, and
.github/workflows/i18n.yml opens a pull request after an English edit
lands. The hand-written README.zh-CN.md is replaced by
i18n/zh-CN/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… orphan and anchor checks, a glossary, pipefail and a main-only job

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…l and banner, link checks in check, concurrent pages and a languages input

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ps every worker, passed pages land, prose-only link checks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ial run; the code-intelligence result states what the three files are

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ints its spend; the localization metric says up to three files, asked for

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the ci/i18n-translations branch from 4563d08 to 63a009a Compare November 13, 2026 06:55
zlareb1 and others added 6 commits November 13, 2026 07:01
…; tests for a stopped run's spend and a stale anchor through check

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…rites it without translating

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…guage-line cost is documented

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 8ac1fe7 into main Nov 13, 2026
41 checks passed
@zlareb1
zlareb1 deleted the ci/i18n-translations branch November 13, 2026 08:01
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