Internationalization

Games use i18next keys instead of inline English strings.

English locale tooling (locale-en)

One CLI merges, checks, and audits English apgames and apresults sources. Entry point: scripts/locale-en.mjs (npm run locale-en).

Default Behaviour
No subcommand check — merged locales/en/apgames.json and locales/en/apresults.json match sources
No namespace token both — run apgames then apresults (aggregate exit code)

After editing English (gameApgamesEn, gameApresultsEn, gameinfo, or shared shards), run one command:

npm run locale-en -- merge --write

That regenerates locales/en/apgames.json and locales/en/apresults.json, updates locale-src/en/apresults/apresults-path-map.json when move-log keys change, and seeds names.{uid} into managed locales (de, fr, it, es-US) when you merge apgames (default both) without reordering managed JSON away from English key order. Commit every file those steps touch.

npm run locale-en                                    # check both (lint + develop/production CI)
npm run locale-en -- merge --write                   # write merged English + path map + managed names
npm run locale-en -- merge apgames --write           # one namespace only (still seeds managed names)
npm run locale-en -- keys --warn --strict --summary  # lint: strict catalog ↔ TS (+ duplicate-en warnings)
npm run locale-en -- remap --write                   # apgames: English src-match; apresults: path-map
npm run locale-en -- prune [--write] [--uid <uid>]   # trim unused gameAp*En export leaves
npm run locale-en -- audit                           # full-registry strict summary
npm run audit-locale                                 # dev-only locale health (orphans, shape, stale MT); see locale-src/en/_locale-audit-allowlist.json
npm run audit-locale -- --output bin/locale-audit.json   # full issue list (JSON); `.txt` for tab-separated lines
npm run audit-locale -- --verbose                  # print every issue to the terminal
npm run locale-en -- help

npm run lint runs npm run locale-en and npm run locale-en -- keys --warn --strict --summary. translate.mjs and locale-prune.mjs call the same merge assert before reading English.

Files

Path Content
locales/en/apgames.json Merged English apgames namespace (committed; what consumers load). Do not edit by hand — run npm run locale-en -- merge --write after editing sources below. See locales/en/README.md.
locale-src/en/apgames/shared/** English shared shards (categories, validation._general, validation._inarow, common buttons, shared status labels). Not machine-translated; not Weblate sidecars.
locale-src/en/apgames/legacy/monolith-slice.json Empty scaffold (registry games use gameinfo + gameApgamesEn).
locales/en/apresults.json Merged nested English apresults namespace. Do not edit by hand — run npm run locale-en -- merge --write after editing sources below.
locale-src/en/apresults/shared/** English _general shards (shared result buckets, ACTOR, global outcomes). Per-game SCRIBE glyph labels live in scribe gameApresultsEn.
locale-src/en/apresults/legacy/monolith-slice.json Empty scaffold; per-game English lives in gameApresultsEn in src/games/<uid>.ts.

Locale JSON on disk uses 2-space indentation and a trailing newline. Scripts (translate, prune-locales, sync-game-names-locale, etc.) share scripts/locale-json-format.mjs; npm run lint runs check-locale-json-format so manual edits stay aligned with --write tools. | locales/{de,fr,it,es-US}/*.json | Translations only (Weblate + CI) | | locale-src/{de,fr,it,es-US}/*.json | English snapshot for machine-translation diffing (CI only) |

locale-src/en/ is authoring input for English only. translate.mjs and locale-prune.mjs still read locales/en/apgames.json and only touch managed locale-src/{de,fr,it,es-US}/ sidecars — never locale-src/en/**.

After changing English shards or legacy slice, run npm run locale-en -- merge --write and commit the updated locales/en/apgames.json (and apresults.json when move-log sources changed). CI lint runs npm run locale-en (merge drift on both namespaces) and npm run locale-en -- keys --warn --strict --summary (duplicate-en warnings + strict full-registry catalog↔TS coverage).

gameinfo may use plain English for description / notes (merged to descriptions.{uid} / notes.{uid}) or legacy apgames:descriptions.{uid} pointers until migrated. Games exporting gameApgamesEn must not keep those pointers. At runtime use the same i18next.t("apgames:…") string literals as unmigrated games; merge copies English from gameApgamesEn into the catalog.

Community partial locales (es, uk, ta, pt, ms, zh-Hans, nb-NO, etc.) live under locales/ with no sidecars. Some folders contain only the categories object in apgames.json where volunteers translated tag labels before other game strings existed.

locale-src/ sidecars

Managed locales (de, fr, it, es-US) are machine-translated by scripts/translate.mjs when English changes on develop (Dev Server CI). The script compares each key against a flat English snapshot in locale-src/ to detect stale translations.

Develop CI order (machine translation)

On develop pushes, Dev Server CI runs:

  1. npm test (includes typecheck via pretest)
  2. npm run locale-en — merged English apgames.json / apresults.json must match sources
  3. locale-prune.mjs — again asserts merged English before reading locales/en/*.json, then prunes managed locales vs English
  4. translate.mjs — same merge assert before translating apgames.json
  5. Auto-commit locales/{de,fr,it,es-US}/ and locale-src/{de,fr,it,es-US}/ only (not locale-src/en/**)

Develop and PR CI (npm run lint and npm run test:scripts on the package build path) run npm run locale-en and full-registry locale-en keys --warn --strict --summary on every change.

When you remove keys from English, develop CI prunes the matching entries from managed locales/ files and locale-src/ sidecars before translation runs (no Gemini API call). Community partial locales are not auto-pruned — they remain Weblate-managed.

When English consolidates copy onto a new leaf path but the English src string is unchanged (shared validation._general.*, renamed stems, etc.), run npm run locale-en -- remap apgames --write before npm run translate. The script updates locale-src tracking and copies translations into locales/{de,fr,it,es-US}/apgames.json (translate requires both; tracking alone is not enough).

For apresults, npm run locale-en -- merge --write already refreshes apresults-path-map.json. Use npm run locale-en -- remap apresults --write when English moves to a new nested path but the string is unchanged (before npm run translate). node scripts/audit-apresults-catalog.mjs --write-map is optional (same path-map output as merge follow-up).

Weblate merges

  1. Merge migration before accepting Weblate PRs that strip _src
  2. Close bulk "Cleanup translation files" PRs — they delete metadata and unrelated keys
  3. Small human-editing PRs merge normally; locale-src/ is never in the diff
  4. In hosted Weblate: disable the "Cleanup translation files" add-on for managed components

Hosted Weblate vs GitHub develop

GitHub origin/l10n/weblate is reset to match develop after imports (npm run merge-weblate-branch). Hosted Weblate also keeps its own git export (weblate/develop remote). Those histories diverge easily; Weblate then reports “Could not merge the repository” for many locales/* files.

Do not resolve that with git merge weblate/develop and checkout --theirs — that drops develop machine translations.

  1. git fetch origin weblate (remote weblate → https://hosted.weblate.org/git/abstract-play/gameslib/)
  2. npm run overlay-weblate-locales -- --ours origin/develop --theirs weblate/develop (pass explicit locale paths, or rely on default diff vs last merge)
  3. Commit and git push origin develop
  4. npm run reset-weblate-export — force-with-lease origin/l10n/weblate to the same commit as origin/develop (you cannot git push to hosted.weblate.org; that remote is read-only)
  5. In Weblate: lock → Repository → Update (or wlc pull) → unlock. If Diagnostics still show merge failures, use Repository maintenance → Reset (admin), then update again.

npm run check-weblate-branch compares origin/develop to origin/l10n/weblate only; hosted Weblate can still be out of date until step 5.

Weblate key naming

Weblate's i18next parser treats a bare key as conflicting with siblings whose names look like plural or context suffixes (_one, _other, _2, _11, etc.) in the same JSON object. For example, do not place INSTRUCTIONS alongside INSTRUCTIONS_one — rename the non-plural key (e.g. INSTRUCTIONS_ANY).

npm run lint runs check-weblate-keys against locales/en/*.json and fails on conflicts. Use a distinct stem for each purpose (e.g. nowhere_what vs nowhere_count_one/nowhere_count_other).

In game code

Migrated games (pilot: Complica — src/games/complica.ts) export English in gameApgamesEn and call i18next.t with literal apgames: keys (same as today):

export const gameApgamesEn = {
    validation: {
        INITIAL_INSTRUCTIONS: "Select the column into which to drop your stone.",
    },
};

// gameinfo — plain English; merge writes descriptions.{uid}
description: "A simple connect-4 game played on a narrow field where the columns never fill up.",

// validation — literal key path (strict checks match export leaves to these refs)
result.message = i18next.t("apgames:validation.complica.INITIAL_INSTRUCTIONS");

Run npm run locale-en -- merge --write and commit locales/en/apgames.json. npm run lint runs full-registry locale-en keys --strict (all migrated games). For a single game while iterating: npm run locale-en -- keys --strict --uid <uid>. Use string literals for per-game keys in that game file so strict ref collection can see them.

Strict catalog ↔ TypeScript checks

npm run locale-en -- keys apgames --strict (or --strict --uid <uid>) compares the merged English catalog to references in game source. Implementation: scripts/lib/locale-en-collectors/apgames.mjs (re-exported from check-apgames-refs.mjs).

Reference collection (missing keys): AST only — no comment text. Counts i18next.t / gameApgamesT, gameApgamesUidKey, neutralAreaLabel / seatAreaLabel, and any string literal whose value is an apgames: key (e.g. getButtons() label fields). Template literals with ${…} are ignored until a suffix allowlist exists (Step 2). Malformed keys without a validation|variants|displays|buttons|status. prefix are skipped for missing checks.

Orphan leaves (export unused): For games that export gameApgamesEn, each per-game leaf under those sections must be referenced in that game’s module (including src/games/<uid>/** submodules). Variants and displays are also satisfied when gameinfo.variants / gameinfo.displays lists the uid or a declared group (#<group> pseudo entries), and when the corresponding keys exist under gameApgamesEn.variants / gameApgamesEn.displays (the checker merges those into the same metadata). Variant and display labels loaded only in shared GameBase do not need literal references in the game file. validation, buttons, and status leaves still need visible refs (i18next.t, string literals, neutralAreaLabel / seatAreaLabel, etc.). names, descriptions, and notes are not required as literals in game TS.

Do not add void gameApgamesUidKey(…) “anchor” lines for variant/display coverage. That pattern is unnecessary when gameinfo and gameApgamesEn agree (the normal case). Use gameApgamesUidKey only when you actually need the key string at runtime (same shape as a literal apgames:… path); strict counts those calls as references, but you should not sprinkle no-op calls to satisfy orphans.

Audit (full registry, one ts-morph load): npm run locale-en -- audit apgames — missing/orphan totals plus top buckets for debt triage.

Plural and context keys: A reference to validation.foo.BAR satisfies catalog leaves BAR_one / BAR_other, and INITIAL_INSTRUCTIONS satisfies INITIAL_INSTRUCTIONS_place and similar context suffixes. Dynamic dual-plural keys built via pinchDualRelocateKey() in pinch.ts are expanded by the collector.

Pruning unused export leaves: npm run locale-en -- prune apgames (dry-run) removes gameApgamesEn properties that strict still reports as orphans after you have wired shared keys or confirmed the string is unused. Use --write to apply; then npm run locale-en -- merge --write.

New games: plain English in gameinfo and gameApgamesEn; do not add per-game leaves to the legacy slice. Use plain English in gameinfo for description/notes (not apgames:descriptions.{uid} pointers). Variant names in gameinfo still resolve via merged variants.{uid}.

apresults (move log)

Runtime keys: apresults:_general.<ResultType>.<leaf> and apresults:<uid>.<ResultType>.<leaf>. Author shared copy under locale-src/en/apresults/shared/_general/ and per-game strings in gameApresultsEn (same pattern as gameApgamesEn). Run npm run locale-en -- merge --write and commit locales/en/apresults.json. npm run locale-en keeps merge output aligned with sources and the path map.

export const gameApresultsEn = {
    PLACE: { default: " placed at ." },
    CAPTURE: {
        one: " captured one piece.",
        other: " captured  pieces.",
    },
};

this.pushSeatChatLine(lines, seat, "apresults:myuid.PLACE.default", { where: r.where! });

Key checks: npm run locale-en -- keys apresults --warn --strict (lint: strict full-registry missing/orphan coverage, same bar as apgames; duplicate English vs _general and duplicate English within _general remain warn-only under --warn). For the full _general internal list: npm run audit-apresults-general-duplicate-en or npm run locale-en -- keys apresults --warn --verbose (optional --general-scope global|perResultType|both; default both skips same-bucket groups in the global pass). Suppress known debt via locale-src/en/apresults/shared/_duplicate-en-allowlist.json (generalInternal paths). npm run locale-en -- keys apresults --strict --uid <uid> and npm run locale-en -- audit apresults compare the merged catalog to apresults: literals in game source (pushSeatChatLine, pushNeutralChatLine, i18next.t, textKey, plus shared lines in GameBase). Collector: scripts/lib/locale-en-collectors/apresults.mjs. Plural stems (DELTA_SCORE_GAIN vs .one / .other) follow the same rules as apgames. scribe.SCRIBE.glyphs.* / scribe.SCRIBE.mini.* are excluded from per-game orphan checks (dynamic templates in scribe.ts).

Machine translation: node scripts/translate.mjs on locales/en/apresults.json calls the same merge assert as npm run locale-en before reading English (mirror apgames.json).

Pruning unused export leaves: npm run locale-en -- prune apresults (dry-run) removes gameApresultsEn properties that strict still reports as orphans after you wire shared _general keys or confirm the string is unused. Use --write to apply; then npm run locale-en -- merge --write.

Variant groups (#<group>)

When gameinfo.variants entries use a group, GameBase synthesizes a #<group> pseudo-variant for record headers and challenge UI. English for the default option in that group lives in gameApgamesEn.variants["#<group>"].name (merged to variants.<uid>.#<group>.name). locale-en keys reports gameinfo pointer violations if any declared group is missing that name. Use quoted keys in TypeScript ("#board": { name: "…" }).

Game titles (names.{uid})

Meta-game display titles use apgames:names.{uid} (e.g. apgames:names.agere → "Adere"). English names come from gameinfo.name in the apgames merge; npm run locale-en -- merge --write (with apgames or both) also seeds managed locales. CI enforces parity with npm run check-game-names-locale.

Descriptions and notes continue to use apgames:descriptions.{uid} and apgames:notes.{uid}.

Category tag labels (categories.*)

Explore filters, game pickers, and meta pages show gameinfo.categories tag ids using localized strings from locales/en/apgames.json → categories. Each tag id has tag, full, and description.

Many keys are dynamic (categories.${tagId}.tag); do not run prune tools that drop unreferenced paths.

Render area labels

Seat-specific stash and panel titles under validation.<game> should use the placeholder (not). Games emit structured labels via seatAreaLabel(); do not call i18next.t() for those labels inside render(). Front resolves keys at draw time. See Structured render labels.

Sidebar status and score table headers use apgames:status.* keys the same way: emit neutralAreaLabel() from sidebarStatuses() / sidebarScores(); front resolves in setStatus().

addResource

Front end merges bundles via APGames.addResource(lang) — see API.

Consumers (front, node-backend, node-backend crons)

Repo Display Notifications
front getGameDisplayName() → resolveGameName(uid, gameinfo.name) after APGames.addResource —
node-backend — localizedGameName() in lib/gameDisplayName.ts; initi18n preloads apgames from gameslib/locales/*
node-backend crons/ — Same pattern in starttournaments.ts for tournament emails

Pin @abstractplay/gameslib via each repo's ci-deps.dev.json / ci-deps.prod.json. Front runs npm run sync-locales after bump to copy updated apgames (including names) into public/locales/.

Scripts

Script Purpose
npm run sync-game-names-locale Regenerate names.{uid} in English from gameinfo.name
npm run seed-game-names-managed-locales Copy English names into de/fr/it/es-US + locale-src (skip MT)
npm run check-game-names-locale Fail when names diverges from registry (part of lint)
npm run translate Gemini incremental translate en → de/fr/it/es-US (names.* never MT; English fill-in only for missing keys). Reuses existing translations when normalized English matches another key in the same locale file; sends one API string per unique English in each batch.
npm run prune-locales Remove stale keys from managed locales + locale-src/ (no API; develop CI runs this before translate)
npm run check-locale-json-format Fail when locales/ or locale-src/ JSON is not canonical 2-space (--write to normalize)
npm run check-weblate-keys Fail on Weblate plural-stem key conflicts in English locales
npm run overlay-weblate-locales Reconcile hosted Weblate export with develop (keep MT; overlay human strings)
npm run reset-weblate-export Force origin/l10n/weblate to match origin/develop (then pull in Weblate UI)
npm run check-locale-readiness Audit locales vs English
npm run locale-en -- merge --write Merge English sources → locales/en/apgames.json and/or apresults.json
npm run locale-en / locale-en -- keys --warn --strict Merge drift check; strict catalog ↔ TS (lint)
npm run locale-en -- remap --write Copy managed translations when English paths move
npm run locale-en -- prune [--write] Dry-run/--write trim unused gameAp*En export leaves
node scripts/publish-locales.mjs --stage dev|prod Upload supported locales to S3

Example games