diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java index 9b0edd82f..fa048cecf 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java @@ -31,6 +31,7 @@ import org.geysermc.geyser.util.AssetUtils; import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.WebUtils; +import javax.annotation.Nullable; import java.io.*; import java.nio.file.Files; import java.util.HashMap; @@ -208,6 +209,23 @@ public class MinecraftLocale { return localeStrings.getOrDefault(messageText, messageText); } + /** + * Translate the given language string into the given locale, or returns null. + * + * @param messageText Language string to translate + * @param locale Locale to translate to + * @return Translated string or null if it was not found in the given locale + */ + @Nullable + public static String getLocaleStringIfPresent(String messageText, String locale) { + Map localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase(Locale.ROOT)); + if (localeStrings != null) { + return localeStrings.get(messageText); + } + + return null; + } + /** * Convert a byte array into a hex string * 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 43e8c69e3..8f4779cb9 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java @@ -45,7 +45,11 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer< @Override public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) { // Get the locale string - String localeString = MinecraftLocale.getLocaleString(key, locale); + String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale); + if (localeString == null) { + // Allow fallback components to take priority + return null; + } // Replace the `%s` with numbered inserts `{0}` Pattern p = stringReplacement; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 22e696f8c..8a4116819 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.12.0-20220629.025215-9" +adventure = "4.13.1-20230408.192716-3" adventure-platform = "4.1.2" junit = "5.9.2" checkerframework = "3.19.0"