Fixed quick chat text injection (#1144)

https://github.com/openfrontio/OpenFrontIO/issues/1035
Fixes #1035

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

regression is found:

.w.

---------

Co-authored-by: Scott Anderson <scottanderson@users.noreply.github.com>
Co-authored-by: evanpelle <evanpelle@gmail.com>
This commit is contained in:
Aotumuri
2025-06-13 09:50:57 -07:00
committed by evanpelle
co-authored by Scott Anderson evanpelle
parent d037aba109
commit 6afd45e464
9 changed files with 41 additions and 53 deletions
+14 -4
View File
@@ -212,10 +212,20 @@ export class EventsDisplay extends LitElement implements Layer {
}
const baseMessage = translateText(`chat.${event.category}.${event.key}`);
const translatedMessage = baseMessage.replace(
/\[([^\]]+)\]/g,
(_, key) => event.variables?.[key] || `[${key}]`,
);
let translatedMessage = baseMessage;
if (event.target) {
try {
const targetPlayer = this.game.player(event.target);
const targetName = targetPlayer?.name() ?? event.target;
translatedMessage = baseMessage.replace("[P1]", targetName);
} catch (e) {
console.warn(
`Failed to resolve player for target ID '${event.target}'`,
e,
);
return;
}
}
this.addEvent({
description: translateText(event.isFrom ? "chat.from" : "chat.to", {