feat(i18n): translate new strings automatically on the PR

Merged
KI
3mo ago
+478-1

Why

Sixteen locales sit behind compile --strict, so every PR that adds an English string owes sixteen translations before CI passes. #6952 already paid this tax by hand. This closes the loop on the PR itself, keeping strict-mode's guarantee (no locale ever ships partially translated) without making "add a button" cost a translation errand.

How

packages/i18n/scripts/translate-missing.ts — finds every empty msgstr, translates each locale's gap in one Claude request anchored to ~40 of that catalog's own existing translations (register and terminology come from the catalog, not a hand-maintained glossary), then validates every fill against the English source: placeholders, tag markers, ICU structure, and the one/few/many/other requirement for ru/pl/cs. A fill that fails validation stays empty — the strict gate then fails loudly rather than a broken string shipping.

Translate Catalogs workflow — on same-repo PRs: extract → count gaps (entry-aware; the PO header is msgid "" and must not count) → translate → re-verify compile --strict + the stale check → push the commit back. The push uses a GitHub App token because GITHUB_TOKEN pushes trigger no workflows and would leave the PR checkless on its newest commit. Fork PRs (no secrets) surface their gap in the existing catalog audit for a maintainer.

Machine fills are a floor, not a ceiling — reword freely in the same PR; the stale-check keys exemptions to exact English text so later edits re-check.

Verification

  • Validator unit tests (8): dropped/renamed placeholders, unbalanced tags, removed ICU, Slavic plurals missing few/many all rejected; faithful translations and reworded ICU prose accepted
  • Counter tested against real catalogs: baseline 0, one blanked entry → 1, restored → 0; skips the en-only-changes.txt exemption file
  • Workflow YAML validated; catalog gate, i18n tests (116), and desktop typecheck green

The live API path first exercises on the next PR that adds a string — the strict compile after the translator means its failure mode is a red check, never a silent merge.

https://claude.ai/code/session_012U97YWVsDvZwQkBaSGEmor


Summary by cubic

Adds a workflow that fills missing locale translations on the PR itself, so adding an English string no longer requires manual translation in all sixteen locales before compile --strict passes.

New Features

  • The Translate Catalogs workflow extracts catalogs, translates empty entries with Claude, verifies compile --strict, and pushes fills back to the PR branch.
  • scripts/translate-missing.ts anchors each locale's fills on that catalog's existing translations and validates placeholders, tag markers, ICU structure, and one/few/many/other for ru/pl/cs; fills that fail stay empty so the strict gate fails loudly.
  • Also runnable locally with bun run --cwd packages/i18n translate.

Rollout notes

  • Pushes use a least-privilege GitHub App token (contents:write) passed only to the push step, since GITHUB_TOKEN pushes trigger no workflows and would leave the PR checkless.
  • Commit and push run with hooks disabled, the token absent from the commit env, and the head ref reaching the shell only as a quoted environment variable, since a branch name can contain shell metacharacters.
  • Checkout persists no credentials and fetches full history so the stale-translation check can resolve its merge base.
  • Fork PRs surface their gap in the existing catalog audit for a maintainer.

Summary by CodeRabbit

  • New Features
    • Added automated translation of missing locale catalog entries during pull requests.
    • Added local translation support with dry-run and locale-specific options.
    • Added validation to preserve placeholders, tags, ICU formatting, and locale-specific plural rules.
    • Added strict checks that reject invalid translations and identify unresolved entries.
  • Documentation
    • Documented the automated translation workflow and local command.
  • Tests
    • Added coverage for translation integrity and ICU formatting validation.