Skip to content

PWA2: Localize the work-area panel and clear-button text - #8

Merged
kramsey458 merged 3 commits into
mainfrom
claude/localize-ui
Sep 22, 2026
Merged

kramsey458 merged 3 commits into
mainfrom
claude/localize-ui

Conversation

@kramsey458

Copy link
Copy Markdown
Collaborator

Summary

The building-panel section and the top-right clear button had their English text hard-coded, so the game had no way to translate it. That text now comes from the game's ILoc, using 10 new keys in Localizations/enUS_PersistentWorkAreas.csv. English players see exactly the same text as before. A translation is now one extra CSV (for example deDE_PersistentWorkAreas.csv).

The change is display only. It adds no tick, save, persistence, Harmony, network or simulation code.

Items

PWA2: localize the work-area UI text

What changed

  • WorkAreaFragment and WorkAreaService now take Timberborn.Localization.ILoc from the container. The game binds it AsSingleton().AsExported() in the Bootstrapper context, so it resolves in the Game context, where game fragments such as DuplicateObjectFragment already inject it.
  • These strings now come from the CSV: the section heading, the checkbox title and tooltip, the ON/OFF badge, the three hints, the clear button's label and its tooltip.
  • The 10 keys are constants in the new source/LocKeys.cs.
  • The clear label is Clear pinned areas ({0}), formatted with the pin count through ILoc.T<int>.
  • The label is built in a new ClearLabel() that catches FormatException. Notify() also runs from OnDeleted, inside the game's EntityDeletedEvent, and EventBus.Post does not catch handler exceptions. Without the guard, a third-party translation with a broken {0} could throw out of entity deletion on that one machine. With the guard, a bad translation logs one error and shows the unformatted text.
  • Log messages stay in English.
  • The README now says where the CSV is, both in the package (version-1.1/Localizations/) and in the repository (packaging/PersistentWorkAreas/version-1.1/Localizations/). It also says how to add a translation and to keep {0}.

Tests (new checks in tests/Program.cs, 38 -> 45)

  1. The CSV follows the game's ID,Text,Comment layout: 3 columns, unique non-empty keys, no trailing spaces, and none of the comma-space-quote patterns that LocalizationCsvValidator treats as critical.
  2. No hard-coded English UI text in the mod DLL. The check reads the DLL's #US string heap with System.Reflection.Metadata, which is in-box on net8.0, so no package is needed. It is an allow-list: every literal must be one of the following, and anything else fails and is listed.
    • an enUS key, or the key-binding id
    • a PersistentWorkAreas* VisualElement name
    • a type or member name of the game outline types the mod reflects on
    • log text
  3. Every LocKeys constant has enUS text and is used by the code. This also means an empty heap cannot make check 2 pass by default.
  4. Every enUS key is used by LocKeys or by a key-binding blueprint.
  5. Both constructors take ILoc.
  6. The ClearAll text contains {0} and formats cleanly.
  7. In the IL, the ClearAll key is loaded and passed to ILoc.T<int> inside a try that catches FormatException.

Fail before: at 6197119 (the unfixed source), check 2 fails and lists the 11 former literals, among them WORKING AREA, Keep working area visible, the tooltip, the three hints, ON, OFF and Clear pinned areas (.

Pass after: 45/45.

Mutation runs (each one rebuilt the DLL and ran Checks, and each was caught):

  • "WORK AREA" as a literal: check 2 fails.
  • "On"/"Off" as literals: check 2 fails.
  • A misspelled raw key "PersistentWorkAreas.Panel.Headin": check 2 fails.
  • A LocKeys constant that the code no longer uses: check 3 fails.
  • A deleted CSV row: check 3 fails.
  • A stale CSV row: check 4 fails.
  • , " spacing in the CSV: check 1 fails.
  • T(ClearAll) without the count: check 7 fails.
  • The guard catching the wrong exception type: check 7 fails.

Tests

Suite Before (6197119) After (3ce9d01)
build.ps1 -GameDir ... (build, Checks, packaging) 38/38 45/45, 0 warnings, 0 errors, packaging OK
dotnet run --project tests/Checks.csproj -c Release -- <game> <dll> <packaging> 38/38 45/45

origin/main has not moved since 6197119, so the rebase was a no-op.

Co-op impact

None. Simulation and the wire format do not change. The only runtime change is where the text of UI elements comes from. The player's language setting can change only that text and its layout. The new FormatException guard removes the one way the language setting could have raised an exception inside a simulation event (EntityDeletedEvent). The manifest Id and Version are unchanged, so the BeaverBuddies Stability Fork's mod-list comparison is not affected. Players do not need to update together.

Proposed CHANGELOG lines

(Not added to CHANGELOG.md.)

  • All UI text now comes from version-1.1/Localizations/enUS_PersistentWorkAreas.csv, so the mod can be translated by adding a <language>_PersistentWorkAreas.csv with the same keys. The English text is unchanged.
  • When updating, replace the whole PersistentWorkAreas folder. The DLL now reads its text from the CSV, so copying only the DLL over 1.0.0 shows raw keys.

Needs in-game testing

  • Single player: select a farm. The panel section should still read WORKING AREA / Keep working area visible, show the tooltip on hover, show the OFF badge, and show the hint "Click to pin this outline while planting or building."
  • Pin it. The badge should become ON, the hint should change to "Pinned after deselection...", and the top-right button should read Clear pinned areas (1). Pin a second building and the button should read (2). Hover the button to check its tooltip. Delete a pinned building and check that the count drops.
  • Player.log should contain no No localization for PersistentWorkAreas. errors.
  • Optional: set the game to a language other than English and load a save. The mod's text should fall back to English, with no raw keys. The game will log its usual Missing or empty localization key PersistentWorkAreas.* warning, one per key, until a translation exists.
  • Two-player BeaverBuddies (optional, because nothing about simulation changed): pin, unpin and clear on one side, and delete a pinned building. There should be no desync.

Review

Three adversarial reviewers approved (lenses: determinism and co-op, save and cross-mod compatibility, and whether the test is real).

Fixed

  • Determinism reviewer (nit): a malformed {0} in a future translation could throw FormatException from Notify(). That would also happen from inside EntityDeletedEvent. Fixed with the guarded ClearLabel() and check 7.
  • Test reviewer (minor): the literal check was a deny-list and missed new or re-cased English ("WORK AREA", "On"/"Off"). It is now an allow-list.
  • Test reviewer (minor): a misspelled raw key passed. It is now caught, because every PersistentWorkAreas.* literal must be an enUS key.
  • Test reviewer (minor): T(ClearAll) without the count passed. It is now caught by the IL call-site check.
  • Test reviewer (nit): the heap scan could pass with nothing in it. Check 3 now requires every LocKeys value to appear among the literals. While testing this I also found that the heap walk reads zero padding as "", and it now skips empty entries.
  • Compatibility reviewer (nit): the README gave the CSV path relative to version-1.1, which confused readers of the repository. It now gives both paths and says to keep {0}.
  • Compatibility reviewer (nit): copying only the DLL over a 1.0.0 folder shows raw keys. This is now in the proposed CHANGELOG line. No code change is needed, because the documented install replaces the whole folder.

Declined or deferred

  • The README ("passes 38 automated lifecycle/API checks") and VALIDATION.md ("38 checks passed") describe the 1.0.0 release build, so they were left alone. Update the counts at the next release, adding PWA1's checks as well.
  • The docs site (FAQ "Is it translated? Not yet", and index "non-English UI text" under Not included) is still accurate, because no translation ships.

Merge notes for sibling branches

  • claude/pin-refresh-planner (PWA1) also edits the WorkAreaService constructor and field block. git merge-tree shows a conflict only there. Keep both constructor parameters. tests/Program.cs merges automatically.
  • claude/checks-ci has not been pushed yet. It adds const int GameChecks = 27 and a count guard right after the "Clear key binding matches input handler" check, which is where this PR's checks are added. When rebasing, keep this PR's checks before that guard and raise GameChecks by 7, to 34, plus any checks PWA1 adds. This PR's static ReadCsv/BlueprintLocKeys helpers can stay after return 0;.

🤖 Generated with Claude Code

kramsey458 and others added 2 commits September 22, 2026 04:59
The building-panel section (heading, checkbox label and tooltip, ON/OFF
badge, the three hints) and the top-right clear button (label with the
pin count, tooltip) were hard-coded English literals, so the game could
not translate them. They now come from 10 new keys in
Localizations/enUS_PersistentWorkAreas.csv through the game's ILoc,
which WorkAreaService and WorkAreaFragment now take from the container.
The keys live in a new LocKeys class. The clear label is
"Clear pinned areas ({0})", formatted with the pin count. The English
text players see is unchanged, and log messages stay in English.

Checks reads the mod DLL's #US string heap with System.Reflection.Metadata
(part of net8.0, so no package is needed) and fails if any former UI
literal or any enUS text is compiled in. It also checks that every LocKeys
constant has enUS text, that every enUS key is used by LocKeys or a
key-binding blueprint, that the CSV follows the game's ID,Text,Comment
rules, that both classes take ILoc, and that the clear label formats
the count. 38 -> 44 checks.

The README now says where the UI text lives and how a translation is
added. Display only: no simulation, save or network change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review follow-ups for the ILoc change.

WorkAreaService.Notify formats "Clear pinned areas ({0})" through
ILoc.T<int>, which calls string.Format with no try/catch. Notify also runs
from OnDeleted, inside the game's EntityDeletedEvent, and EventBus.Post
does not catch handler exceptions. A translation file with a broken {0}
would therefore throw out of entity deletion on that one machine. The
label now comes from ClearLabel(), which catches FormatException, logs it
and falls back to the unformatted text. The shipped enUS text formats
cleanly, so nothing changes for players.

Checks:
- The DLL string check is now an allow-list. Every #US literal must be a
  key in the enUS CSV (or the key-binding id), a PersistentWorkAreas*
  element name, a type or member name of the game outline types the mod
  reflects on, or log text. A new or re-cased English label such as
  "WORK AREA" or "On" now fails, and so does a misspelled raw key.
- Every LocKeys constant must also be used by the code, which also stops
  the literal scan from passing on an empty heap.
- The IL must load the ClearAll key and call ILoc.T<int> with it inside a
  try that catches FormatException.
- 44 -> 45 checks.

The README now gives the CSV's path both in the package and in the
repository, and says to keep {0} in a translation of the clear label.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Keep PWA2's localization checks above the GameChecks count guard and
raise GameChecks from 27 to 34. Full run: 45/45; no-argument run: 11
passed, 34 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kramsey458
kramsey458 marked this pull request as ready for review September 22, 2026 16:39
@kramsey458
kramsey458 merged commit e65bbff into main Sep 22, 2026
1 check passed
kramsey458 added a commit that referenced this pull request Sep 22, 2026
- WorkAreaService constructor: keep PWA1's NavigationDistance parameter,
  _reach and _planner alongside PWA2's ILoc.
- tests/Program.cs: keep the planner checks above the game-free split so
  CI runs them, and raise GameChecks from 34 to 42. Full run: 74/74;
  no-argument run: 32 passed, 42 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kramsey458 added a commit that referenced this pull request Sep 22, 2026
- WorkAreaService constructor: keep PWA4's EntityComponentRegistry and
  PWA2's ILoc.
- tests/Program.cs: move the planting-rule and planner Show checks above
  the game-free split so CI runs them, and raise GameChecks to 56.
  Full run: 104/104; no-argument run: 48 passed, 56 skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kramsey458 kramsey458 mentioned this pull request Sep 22, 2026
@kramsey458
kramsey458 deleted the claude/localize-ui branch September 22, 2026 16:50
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