From dd0854b78fe69459da6510a4e24bbc44ff6f5a81 Mon Sep 17 00:00:00 2001 From: RettichLP Date: Sat, 25 Apr 2026 16:11:03 +0200 Subject: [PATCH 1/3] fix: use translatable notifications --- .../ucutils/common/api/ApiException.java | 3 +- .../widgets/base/AbstractUCUtilsWidget.java | 3 +- .../rettichlp/ucutils/common/models/Job.java | 3 +- .../common/services/NotificationService.java | 39 +++++++------------ .../ucutils/common/services/SyncService.java | 17 ++++---- .../resources/assets/ucutils/lang/de_de.json | 5 +++ .../resources/assets/ucutils/lang/en_gb.json | 5 +++ .../resources/assets/ucutils/lang/en_us.json | 5 +++ 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/main/java/de/rettichlp/ucutils/common/api/ApiException.java b/src/main/java/de/rettichlp/ucutils/common/api/ApiException.java index 22c44e01..03f1abc8 100644 --- a/src/main/java/de/rettichlp/ucutils/common/api/ApiException.java +++ b/src/main/java/de/rettichlp/ucutils/common/api/ApiException.java @@ -7,6 +7,7 @@ import static de.rettichlp.ucutils.UCUtils.LOGGER; import static de.rettichlp.ucutils.UCUtils.notificationService; +import static net.minecraft.text.Text.translatable; @Getter public class ApiException extends RuntimeException { @@ -24,7 +25,7 @@ public ApiException(@NotNull HttpResponse response, String message) { } public void sendNotification() { - notificationService.sendErrorNotification("Fehler bei der Abfrage (" + this.response.statusCode() + ")"); + notificationService.sendErrorNotification(translatable("ucutils.notification.error.api", this.response.statusCode())); } public void log() { diff --git a/src/main/java/de/rettichlp/ucutils/common/gui/widgets/base/AbstractUCUtilsWidget.java b/src/main/java/de/rettichlp/ucutils/common/gui/widgets/base/AbstractUCUtilsWidget.java index e866c3f4..b6261389 100644 --- a/src/main/java/de/rettichlp/ucutils/common/gui/widgets/base/AbstractUCUtilsWidget.java +++ b/src/main/java/de/rettichlp/ucutils/common/gui/widgets/base/AbstractUCUtilsWidget.java @@ -21,6 +21,7 @@ import static de.rettichlp.ucutils.common.gui.widgets.base.AbstractUCUtilsWidget.Alignment.RIGHT; import static java.util.Objects.isNull; import static java.util.Optional.ofNullable; +import static net.minecraft.text.Text.translatable; @Getter public abstract class AbstractUCUtilsWidget { @@ -94,7 +95,7 @@ public void loadConfiguration() { this.widgetConfiguration.setX(getDefaultX()); this.widgetConfiguration.setY(getDefaultY()); } catch (Exception e) { - notificationService.sendErrorNotification("Konfiguration konnte nicht geladen werden"); + notificationService.sendErrorNotification(translatable("ucutils.notification.error.configuration")); LOGGER.error("Could not load configuration for widget {}", registryName, e); } diff --git a/src/main/java/de/rettichlp/ucutils/common/models/Job.java b/src/main/java/de/rettichlp/ucutils/common/models/Job.java index 3b8b8068..cb91cccf 100644 --- a/src/main/java/de/rettichlp/ucutils/common/models/Job.java +++ b/src/main/java/de/rettichlp/ucutils/common/models/Job.java @@ -5,7 +5,6 @@ import java.time.Duration; import java.util.regex.Pattern; -import static de.rettichlp.ucutils.UCUtils.notificationService; import static de.rettichlp.ucutils.UCUtils.storage; import static java.time.Duration.ofMinutes; import static java.util.regex.Pattern.compile; @@ -47,6 +46,6 @@ public enum Job { } public void startCountdown() { - storage.getCountdowns().add(new Countdown(this.displayName, this.cooldown, () -> notificationService.sendInfoNotification("Cooldown für '" + this.displayName + "' abgelaufen"))); + storage.getCountdowns().add(new Countdown(this.displayName, this.cooldown, () -> {})); } } diff --git a/src/main/java/de/rettichlp/ucutils/common/services/NotificationService.java b/src/main/java/de/rettichlp/ucutils/common/services/NotificationService.java index a4bb5b13..bb97fd31 100644 --- a/src/main/java/de/rettichlp/ucutils/common/services/NotificationService.java +++ b/src/main/java/de/rettichlp/ucutils/common/services/NotificationService.java @@ -3,7 +3,6 @@ import de.rettichlp.ucutils.common.gui.widgets.NotificationWidget; import lombok.Data; import net.minecraft.text.Text; -import org.jetbrains.annotations.NotNull; import java.awt.Color; import java.time.LocalDateTime; @@ -13,9 +12,7 @@ import java.util.List; import java.util.Objects; import java.util.UUID; -import java.util.function.Supplier; -import static de.rettichlp.ucutils.UCUtils.renderService; import static java.awt.Color.CYAN; import static java.awt.Color.GREEN; import static java.awt.Color.ORANGE; @@ -31,30 +28,25 @@ public class NotificationService { private final Collection notifications = new ArrayList<>(); - public void sendSuccessNotification(String message) { - sendNotification(message, GREEN, 5000); + public void sendSuccessNotification(Text text) { + sendNotification(text, GREEN, 5000); } - public void sendInfoNotification(String message) { - sendNotification(message, CYAN, 5000); + public void sendInfoNotification(Text text) { + sendNotification(text, CYAN, 5000); } - public void sendWarningNotification(String message) { - sendNotification(message, ORANGE, 5000); + public void sendWarningNotification(Text text) { + sendNotification(text, ORANGE, 5000); } - public void sendErrorNotification(String message) { - sendNotification(message, RED, 5000); + public void sendErrorNotification(Text text) { + sendNotification(text, RED, 5000); } - public void sendNotification(String message, Color color, long durationInMillis) { - sendNotification(() -> Text.of(message), color, durationInMillis); - } - - public void sendNotification(@NotNull Supplier messageSupplier, Color color, long durationInMillis) { - Notification notification = new Notification(messageSupplier, durationInMillis); - notification.setBorderColor(color); - notification.setBackgroundColor(renderService.getSecondaryColor(color)); + public void sendNotification(Text text, Color color, long durationInMillis) { + Notification notification = new Notification(text, durationInMillis); + notification.setColor(color); this.notifications.add(notification); } @@ -70,15 +62,14 @@ public List getActiveNotifications() { public static class Notification { private final UUID id = randomUUID(); - private final Supplier textSupplier; + private final Text text; private final long durationInMillis; private final LocalDateTime timestamp = now(); - private Color borderColor = WHITE; - private Color backgroundColor = renderService.getSecondaryColor(WHITE); + private Color color = WHITE; @Override public int hashCode() { - return hash(this.id, this.textSupplier, this.durationInMillis, this.timestamp, this.borderColor, this.backgroundColor); + return hash(this.id, this.text, this.durationInMillis, this.timestamp, this.color); } @Override @@ -87,7 +78,7 @@ public boolean equals(Object o) { } public NotificationWidget toWidget() { - return new NotificationWidget(this.getTextSupplier().get(), this.borderColor, this.timestamp, this.durationInMillis); + return new NotificationWidget(this.text, this.color, this.timestamp, this.durationInMillis); } } } diff --git a/src/main/java/de/rettichlp/ucutils/common/services/SyncService.java b/src/main/java/de/rettichlp/ucutils/common/services/SyncService.java index 0b159465..1c8236a8 100644 --- a/src/main/java/de/rettichlp/ucutils/common/services/SyncService.java +++ b/src/main/java/de/rettichlp/ucutils/common/services/SyncService.java @@ -19,7 +19,8 @@ import static java.util.Objects.nonNull; import static java.util.concurrent.TimeUnit.MINUTES; import static net.minecraft.text.Text.empty; -import static net.minecraft.text.Text.of; +import static net.minecraft.text.Text.literal; +import static net.minecraft.text.Text.translatable; import static net.minecraft.util.Formatting.DARK_GRAY; import static net.minecraft.util.Formatting.GRAY; import static net.minecraft.util.Formatting.GREEN; @@ -68,7 +69,7 @@ public void syncFactionSpecificData() { utilService.delayedAction(() -> { this.gameSyncProcessActive = false; - notificationService.sendSuccessNotification("Fraktionsdaten synchronisiert"); + notificationService.sendSuccessNotification(translatable("ucutils.notification.info.faction_data_synchronized")); }, COMMAND_COOLDOWN_MILLIS * 2); } @@ -83,12 +84,12 @@ public void checkForUpdates() { String currentVersion = utilService.getVersion(); if (nonNull(latestVersion) && !currentVersion.equals(latestVersion)) { - notificationService.sendNotification(() -> empty() - .append(of("Neue UCUtils Version verfügbar").copy().formatted(GRAY)) - .append(of(":").copy().formatted(DARK_GRAY)).append(" ") - .append(of(currentVersion).copy().formatted(RED)).append(" ") - .append(of("→").copy().formatted(GRAY)).append(" ") - .append(of(latestVersion).copy().formatted(GREEN)), MAGENTA, MINUTES.toMillis(5)); + notificationService.sendNotification(empty() + .append(translatable("ucutils.notification.info.new_version").copy().formatted(GRAY)) + .append(literal(":").copy().formatted(DARK_GRAY)).append(" ") + .append(literal(currentVersion).copy().formatted(RED)).append(" ") + .append(literal("→").copy().formatted(GRAY)).append(" ") + .append(literal(latestVersion).copy().formatted(GREEN)), MAGENTA, MINUTES.toMillis(5)); } }); } diff --git a/src/main/resources/assets/ucutils/lang/de_de.json b/src/main/resources/assets/ucutils/lang/de_de.json index 38924c77..66df2dce 100644 --- a/src/main/resources/assets/ucutils/lang/de_de.json +++ b/src/main/resources/assets/ucutils/lang/de_de.json @@ -21,6 +21,11 @@ "ucutils.inventory.crystals": "Kristalle", "ucutils.inventory.grab_bag": "Wundertüte", + "ucutils.notification.error.api": "Fehler bei der API Abfrage (%s)", + "ucutils.notification.error.configuration": "Konfiguration konnte nicht geladen werden", + "ucutils.notification.info.faction_data_synchronized": "Fraktionsdaten synchronisiert", + "ucutils.notification.info.new_version": "Neue UCUtils Version verfügbar", + "ucutils.options.text.additional": "Erweitert", "ucutils.options.text.amount": "Menge", "ucutils.options.text.automation": "Automatisierung", diff --git a/src/main/resources/assets/ucutils/lang/en_gb.json b/src/main/resources/assets/ucutils/lang/en_gb.json index ba39add9..3d26779d 100644 --- a/src/main/resources/assets/ucutils/lang/en_gb.json +++ b/src/main/resources/assets/ucutils/lang/en_gb.json @@ -21,6 +21,11 @@ "ucutils.inventory.crystals": "Crystals", "ucutils.inventory.grab_bag": "Grab bag", + "ucutils.notification.error.api": "API request error (%s)", + "ucutils.notification.error.configuration": "Configuration could not be loaded", + "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", + "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.options.text.additional": "Additional", "ucutils.options.text.amount": "Amount", "ucutils.options.text.automation": "Automation", diff --git a/src/main/resources/assets/ucutils/lang/en_us.json b/src/main/resources/assets/ucutils/lang/en_us.json index ba39add9..3d26779d 100644 --- a/src/main/resources/assets/ucutils/lang/en_us.json +++ b/src/main/resources/assets/ucutils/lang/en_us.json @@ -21,6 +21,11 @@ "ucutils.inventory.crystals": "Crystals", "ucutils.inventory.grab_bag": "Grab bag", + "ucutils.notification.error.api": "API request error (%s)", + "ucutils.notification.error.configuration": "Configuration could not be loaded", + "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", + "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.options.text.additional": "Additional", "ucutils.options.text.amount": "Amount", "ucutils.options.text.automation": "Automation", From b0403ef0897b27ff9ff99cb2a20d487db5fcaf01 Mon Sep 17 00:00:00 2001 From: RettichLP Date: Sun, 26 Apr 2026 14:20:51 +0200 Subject: [PATCH 2/3] feat: update ToggledChat messages to use translatable texts across languages --- .../java/de/rettichlp/ucutils/common/Storage.java | 12 +++++++----- src/main/resources/assets/ucutils/lang/de_de.json | 4 ++++ src/main/resources/assets/ucutils/lang/en_gb.json | 4 ++++ src/main/resources/assets/ucutils/lang/en_us.json | 4 ++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/rettichlp/ucutils/common/Storage.java b/src/main/java/de/rettichlp/ucutils/common/Storage.java index d3a2e953..3d5a6800 100644 --- a/src/main/java/de/rettichlp/ucutils/common/Storage.java +++ b/src/main/java/de/rettichlp/ucutils/common/Storage.java @@ -17,6 +17,7 @@ import lombok.Getter; import lombok.Setter; import net.minecraft.entity.vehicle.MinecartEntity; +import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -32,6 +33,7 @@ import static de.rettichlp.ucutils.common.models.Faction.NULL; import static java.util.Arrays.stream; import static java.util.Optional.ofNullable; +import static net.minecraft.text.Text.translatable; public class Storage { @@ -189,12 +191,12 @@ public void trackReinforcement(Reinforcement reinforcement) { @AllArgsConstructor public enum ToggledChat { - NONE("", "Dauerhafter Chat deaktiviert"), - D_CHAT("d", "Dauerhafter D-Chat aktiviert"), - F_CHAT("f", "Dauerhafter F-Chat aktiviert"), - W_CHAT("w", "Dauerhafter Flüster-Chat aktiviert"); + NONE("", translatable("ucutils.notification.toggled_chat.none")), + D_CHAT("d", translatable("ucutils.notification.toggled_chat.d")), + F_CHAT("f", translatable("ucutils.notification.toggled_chat.f")), + W_CHAT("w", translatable("ucutils.notification.toggled_chat.w")); private final String command; - private final String toggleMessage; + private final Text toggleMessage; } } diff --git a/src/main/resources/assets/ucutils/lang/de_de.json b/src/main/resources/assets/ucutils/lang/de_de.json index 66df2dce..699da7d2 100644 --- a/src/main/resources/assets/ucutils/lang/de_de.json +++ b/src/main/resources/assets/ucutils/lang/de_de.json @@ -25,6 +25,10 @@ "ucutils.notification.error.configuration": "Konfiguration konnte nicht geladen werden", "ucutils.notification.info.faction_data_synchronized": "Fraktionsdaten synchronisiert", "ucutils.notification.info.new_version": "Neue UCUtils Version verfügbar", + "ucutils.notification.toggled_chat.none": "Dauerhafter Chat deaktiviert", + "ucutils.notification.toggled_chat.f": "Dauerhafter F-Chat aktiviert", + "ucutils.notification.toggled_chat.d": "Dauerhafter D-Chat aktiviert", + "ucutils.notification.toggled_chat.w": "Dauerhaftes Flüstern aktiviert", "ucutils.options.text.additional": "Erweitert", "ucutils.options.text.amount": "Menge", diff --git a/src/main/resources/assets/ucutils/lang/en_gb.json b/src/main/resources/assets/ucutils/lang/en_gb.json index 3d26779d..b342e391 100644 --- a/src/main/resources/assets/ucutils/lang/en_gb.json +++ b/src/main/resources/assets/ucutils/lang/en_gb.json @@ -25,6 +25,10 @@ "ucutils.notification.error.configuration": "Configuration could not be loaded", "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.notification.toggled_chat.none": "Persistent chat disabled", + "ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled", + "ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled", + "ucutils.notification.toggled_chat.w": "Persistent whispering enabled", "ucutils.options.text.additional": "Additional", "ucutils.options.text.amount": "Amount", diff --git a/src/main/resources/assets/ucutils/lang/en_us.json b/src/main/resources/assets/ucutils/lang/en_us.json index 3d26779d..b342e391 100644 --- a/src/main/resources/assets/ucutils/lang/en_us.json +++ b/src/main/resources/assets/ucutils/lang/en_us.json @@ -25,6 +25,10 @@ "ucutils.notification.error.configuration": "Configuration could not be loaded", "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.notification.toggled_chat.none": "Persistent chat disabled", + "ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled", + "ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled", + "ucutils.notification.toggled_chat.w": "Persistent whispering enabled", "ucutils.options.text.additional": "Additional", "ucutils.options.text.amount": "Amount", From 44cd6f8ae19697d925661f72dede78dde440f82d Mon Sep 17 00:00:00 2001 From: RettichLP Date: Sun, 26 Apr 2026 14:26:45 +0200 Subject: [PATCH 3/3] feat: add translatable notification for screenshot saved message --- src/main/java/de/rettichlp/ucutils/mixin/ChatScreenMixin.java | 3 ++- src/main/resources/assets/ucutils/lang/de_de.json | 1 + src/main/resources/assets/ucutils/lang/en_gb.json | 1 + src/main/resources/assets/ucutils/lang/en_us.json | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/rettichlp/ucutils/mixin/ChatScreenMixin.java b/src/main/java/de/rettichlp/ucutils/mixin/ChatScreenMixin.java index fc0221b9..19d92b53 100644 --- a/src/main/java/de/rettichlp/ucutils/mixin/ChatScreenMixin.java +++ b/src/main/java/de/rettichlp/ucutils/mixin/ChatScreenMixin.java @@ -13,6 +13,7 @@ import static de.rettichlp.ucutils.common.models.ScreenshotType.OTHER; import static de.rettichlp.ucutils.common.models.ScreenshotType.fromDisplayName; import static java.lang.Thread.sleep; +import static net.minecraft.text.Text.translatable; @Mixin(ChatScreen.class) public abstract class ChatScreenMixin { @@ -23,7 +24,7 @@ public abstract class ChatScreenMixin { if (messageParts.length >= 2 && message.startsWith("/screenshot ")) { String screenshotTypeString = messageParts[1].toLowerCase(); ScreenshotType screenshotType = fromDisplayName(screenshotTypeString).orElse(OTHER); - screenshotType.take(file -> notificationService.sendInfoNotification("Screenshot gespeichert: '" + file.getName() + "'")); + screenshotType.take(file -> notificationService.sendInfoNotification(translatable("ucutils.notification.info.screenshot_saved", file.getName()))); try { sleep(5); diff --git a/src/main/resources/assets/ucutils/lang/de_de.json b/src/main/resources/assets/ucutils/lang/de_de.json index 699da7d2..15e4721e 100644 --- a/src/main/resources/assets/ucutils/lang/de_de.json +++ b/src/main/resources/assets/ucutils/lang/de_de.json @@ -25,6 +25,7 @@ "ucutils.notification.error.configuration": "Konfiguration konnte nicht geladen werden", "ucutils.notification.info.faction_data_synchronized": "Fraktionsdaten synchronisiert", "ucutils.notification.info.new_version": "Neue UCUtils Version verfügbar", + "ucutils.notification.info.screenshot_saved": "Screenshot gespeichert: '%s'", "ucutils.notification.toggled_chat.none": "Dauerhafter Chat deaktiviert", "ucutils.notification.toggled_chat.f": "Dauerhafter F-Chat aktiviert", "ucutils.notification.toggled_chat.d": "Dauerhafter D-Chat aktiviert", diff --git a/src/main/resources/assets/ucutils/lang/en_gb.json b/src/main/resources/assets/ucutils/lang/en_gb.json index b342e391..b1a4017d 100644 --- a/src/main/resources/assets/ucutils/lang/en_gb.json +++ b/src/main/resources/assets/ucutils/lang/en_gb.json @@ -25,6 +25,7 @@ "ucutils.notification.error.configuration": "Configuration could not be loaded", "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.notification.info.screenshot_saved": "Screenshot saved: '%s'", "ucutils.notification.toggled_chat.none": "Persistent chat disabled", "ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled", "ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled", diff --git a/src/main/resources/assets/ucutils/lang/en_us.json b/src/main/resources/assets/ucutils/lang/en_us.json index b342e391..b1a4017d 100644 --- a/src/main/resources/assets/ucutils/lang/en_us.json +++ b/src/main/resources/assets/ucutils/lang/en_us.json @@ -25,6 +25,7 @@ "ucutils.notification.error.configuration": "Configuration could not be loaded", "ucutils.notification.info.faction_data_synchronized": "Faction data synchronized", "ucutils.notification.info.new_version": "New UCUtils version available", + "ucutils.notification.info.screenshot_saved": "Screenshot saved: '%s'", "ucutils.notification.toggled_chat.none": "Persistent chat disabled", "ucutils.notification.toggled_chat.f": "Persistent F-Chat enabled", "ucutils.notification.toggled_chat.d": "Persistent D-Chat enabled",