Repository navigation
PWA2: Localize the work-area panel and clear-button text - #8
Merged
Merged
Conversation
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>
This was referenced Sep 22, 2026
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
marked this pull request as ready for review
September 22, 2026 16:39
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>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inLocalizations/enUS_PersistentWorkAreas.csv. English players see exactly the same text as before. A translation is now one extra CSV (for exampledeDE_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
WorkAreaFragmentandWorkAreaServicenow takeTimberborn.Localization.ILocfrom the container. The game binds itAsSingleton().AsExported()in the Bootstrapper context, so it resolves in the Game context, where game fragments such asDuplicateObjectFragmentalready inject it.source/LocKeys.cs.Clear pinned areas ({0}), formatted with the pin count throughILoc.T<int>.ClearLabel()that catchesFormatException.Notify()also runs fromOnDeleted, inside the game'sEntityDeletedEvent, andEventBus.Postdoes 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.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)ID,Text,Commentlayout: 3 columns, unique non-empty keys, no trailing spaces, and none of the comma-space-quote patterns thatLocalizationCsvValidatortreats as critical.#USstring heap withSystem.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.PersistentWorkAreas*VisualElement nameLocKeysconstant has enUS text and is used by the code. This also means an empty heap cannot make check 2 pass by default.LocKeysor by a key-binding blueprint.ILoc.{0}and formats cleanly.ILoc.T<int>inside atrythat catchesFormatException.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,OFFandClear 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."PersistentWorkAreas.Panel.Headin": check 2 fails.LocKeysconstant that the code no longer uses: check 3 fails., "spacing in the CSV: check 1 fails.T(ClearAll)without the count: check 7 fails.Tests
build.ps1 -GameDir ...(build, Checks, packaging)dotnet run --project tests/Checks.csproj -c Release -- <game> <dll> <packaging>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
FormatExceptionguard removes the one way the language setting could have raised an exception inside a simulation event (EntityDeletedEvent). The manifestIdandVersionare 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.)version-1.1/Localizations/enUS_PersistentWorkAreas.csv, so the mod can be translated by adding a<language>_PersistentWorkAreas.csvwith the same keys. The English text is unchanged.PersistentWorkAreasfolder. 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
No localization for PersistentWorkAreas.errors.Missing or empty localization key PersistentWorkAreas.*warning, one per key, until a translation exists.Review
Three adversarial reviewers approved (lenses: determinism and co-op, save and cross-mod compatibility, and whether the test is real).
Fixed
{0}in a future translation could throwFormatExceptionfromNotify(). That would also happen from insideEntityDeletedEvent. Fixed with the guardedClearLabel()and check 7."WORK AREA","On"/"Off"). It is now an allow-list.PersistentWorkAreas.*literal must be an enUS key.T(ClearAll)without the count passed. It is now caught by the IL call-site check.LocKeysvalue 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.version-1.1, which confused readers of the repository. It now gives both paths and says to keep{0}.Declined or deferred
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.Merge notes for sibling branches
claude/pin-refresh-planner(PWA1) also edits theWorkAreaServiceconstructor and field block.git merge-treeshows a conflict only there. Keep both constructor parameters.tests/Program.csmerges automatically.claude/checks-cihas not been pushed yet. It addsconst int GameChecks = 27and 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 raiseGameChecksby 7, to 34, plus any checks PWA1 adds. This PR's staticReadCsv/BlueprintLocKeyshelpers can stay afterreturn 0;.🤖 Generated with Claude Code