fix: translate unit names in event panel messages#3242
fix: translate unit names in event panel messages#3242slegarraga wants to merge 3 commits intoopenfrontio:mainfrom
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 WalkthroughWhen handling Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/client/graphics/layers/EventsDisplay.ts`:
- Around line 387-391: In EventsDisplay.ts, avoid assigning the raw i18n key
string back into params.unit when translateText fails: capture the original unit
string before transforming (e.g., const raw = params.unit), call
translateText(unitKey), then if the returned value is the same as the key or
otherwise falsy, keep params.unit = raw (or a capitalized/raw fallback) instead
of the translation; update the block that computes unitKey/params.unit to
perform this guarded assignment so missing translations show the original unit
instead of "unit_type.xxx".
|
@slegarraga What if a developer (not knowing about the need for translation) just puts "building: unit.type()"? They'll test using English and it will work. We can't be sure they'll use "unit" as a key name. And also, how can we be sure they'll send a unit translation key string, and not just untranslatable unit.type()? I think what we can do is:
|
Address review feedback: - Check all string params against unit_type translations, not just 'unit' - Keep original value if no translation exists (avoids showing raw keys)
|
Thanks for the feedback @VariableVince! Great point — I've updated the approach in my latest commits to do exactly that: iterate over all string params generically (regardless of key name), attempt to translate each as a Also fixed the Prettier formatting issue. |
| const params = { ...(event.params ?? {}) }; | ||
| for (const key of Object.keys(params)) { | ||
| const value = params[key]; | ||
| if (typeof value === "string") { | ||
| const unitKey = "unit_type." + value.toLowerCase().replace(/ /g, "_"); | ||
| const translated = translateText(unitKey); | ||
| if (translated !== unitKey) { | ||
| params[key] = translated; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
maybe this should go in translateText() instead? that way we'll automatically translate units if we render unit names somewhere else in the UI.
Fixes #3071
Problem
Unit names in event panel messages show raw English type strings (e.g.,
Port) instead of translated names (e.g., DutchHaven).Solution
In
EventsDisplay.ts, before interpolating event message params, theunitparam is now translated viatranslateText("unit_type.<key>")— converting the raw unit type string (e.g.,Port) to its translation key (e.g.,unit_type.port).This affects all three event messages that include unit names:
unit_captured_by_enemycaptured_enemy_unitunit_destroyedChanges
src/client/graphics/layers/EventsDisplay.ts: Translate theunitparam before passing totranslateText()Happy to iterate on feedback!