From 0f3d5c58595c5f1fe4ec9a9e976236e81646db1f Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:07:55 -0400 Subject: [PATCH] Allow fallback components to translate with arguments --- .../geyser/text/MinecraftTranslationRegistry.java | 14 ++++++++++++-- gradle/libs.versions.toml | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java index 8f4779cb9..aaab65c9f 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java @@ -42,13 +42,23 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer< private final Pattern stringReplacement = Pattern.compile("%s"); private final Pattern positionalStringReplacement = Pattern.compile("%([0-9]+)\\$s"); + // Exists to maintain compatibility with Velocity's older Adventure version @Override public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) { + return this.translate(key, null, locale); + } + + @Override + protected @Nullable MessageFormat translate(@Nonnull String key, @Nullable String fallback, @Nonnull String locale) { // Get the locale string String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale); if (localeString == null) { - // Allow fallback components to take priority - return null; + if (fallback == null) { + // No fallback and no match for string; nothing will be translated/inserted + return null; + } + // Fallback strings will still have their params inserted + localeString = fallback; } // Replace the `%s` with numbered inserts `{0}` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8a4116819..a2223abf7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ protocol = "3.0.0.Beta1-SNAPSHOT" raknet = "0.0.1.Final-SNAPSHOT" mcauthlib = "d9d773e" mcprotocollib = "1.19.4-math2-SNAPSHOT" -adventure = "4.13.1-20230408.192716-3" +adventure = "4.14.0-20230418.205641-5" adventure-platform = "4.1.2" junit = "5.9.2" checkerframework = "3.19.0"