Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public InteractionResult use(Level level, Player player, InteractionHand hand) {
40, 0.8, 1.2, 0.8, 0.2);

// Broadcast summoning message to all nearby players
Component summonMsg = Component.translatable("message.israel_simulator.bibi_summoned_by_star")
Component summonMsg = Component.translatable("message.israel_simulator.bibi_summoned_by_star", player.getDisplayName())
.withStyle(ChatFormatting.GOLD, ChatFormatting.BOLD);
AABB broadcastArea = player.getBoundingBox().inflate(96.0);
for (Player p : serverLevel.getEntitiesOfClass(Player.class, broadcastArea)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,4 +490,29 @@ void testAllModMobEffectsHaveTextures() {
}
}
}

@Test
@DisplayName("Translatable messages with %s placeholders receive arguments")
void testTranslatablePlaceholdersHaveArguments() throws IOException {
JsonObject lang;
try (FileReader reader = new FileReader(RESOURCES_PATH.resolve(Paths.get(
"assets", IsraelSimulator.MOD_ID, "lang", "en_us.json")).toFile())) {
lang = GSON.fromJson(reader, JsonObject.class);
}
Pattern noArgs = Pattern.compile("translatable\\(\\s*\"([^\"]+)\"\\s*\\)");
List<String> problems = new ArrayList<>();
try (Stream<Path> files = Files.walk(Path.of("src/main/java"))) {
for (Path file : files.filter(p -> p.toString().endsWith(".java")).toList()) {
Matcher m = noArgs.matcher(Files.readString(file));
while (m.find()) {
JsonElement value = lang.get(m.group(1));
if (value != null && value.getAsString().contains("%")) {
problems.add(file.getFileName() + ": " + m.group(1));
}
}
}
}
assertTrue(problems.isEmpty(), "Placeholders without arguments: " + problems);
}

}
5 changes: 5 additions & 0 deletions test.md
Original file line number Diff line number Diff line change
Expand Up @@ -948,3 +948,8 @@ Non provato dall'utente in gioco.
- Musica stereo: `music/klezmer` (59 s, bulgar originale in modo freygish) e `music/shabbat_shalom` (56 s, brano calmo in re maggiore).
- Il nuovo test `testCustomSoundFilesExist` fallisce se un suono custom di `sounds.json` non ha il suo file Ogg o se il file è vuoto.
- Da sapere: `kirk_boss_theme.ogg` è identico byte per byte a `bibi_boss_theme.ogg`, cioè i due boss hanno la stessa musica.

## Messaggio della Stella di Davide con "%s" al posto del nome
- Problema riscontrato: quando si evoca Bibi con la Stella di Davide la chat mostra "%s used the Star of David. Bibi is here!". Il nome del giocatore non c'è.
- Funzionamento atteso: "Dev used the Star of David. Bibi is here!" (in italiano "Dev ha usato la Stella di Davide...").
- Soluzione: `StarOfDavidItem` passa a `Component.translatable` il nome del giocatore come argomento. Il nuovo test `testTranslatablePlaceholdersHaveArguments` cerca nel codice i messaggi tradotti che contengono `%s` ma vengono creati senza argomenti.
Loading