3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Allow fallback components to translate properly

Fixes #3660
Dieser Commit ist enthalten in:
Camotoy 2023-04-08 15:49:55 -04:00
Ursprung f83235cf96
Commit 11c277481f
3 geänderte Dateien mit 24 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import org.geysermc.geyser.util.AssetUtils;
import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.FileUtils;
import org.geysermc.geyser.util.WebUtils; import org.geysermc.geyser.util.WebUtils;
import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.HashMap;
@ -208,6 +209,23 @@ public class MinecraftLocale {
return localeStrings.getOrDefault(messageText, messageText); 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<String, String> 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 * Convert a byte array into a hex string
* *

Datei anzeigen

@ -45,7 +45,11 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer<
@Override @Override
public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) { public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) {
// Get the locale string // 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}` // Replace the `%s` with numbered inserts `{0}`
Pattern p = stringReplacement; Pattern p = stringReplacement;

Datei anzeigen

@ -13,7 +13,7 @@ protocol = "3.0.0.Beta1-SNAPSHOT"
raknet = "0.0.1.Final-SNAPSHOT" raknet = "0.0.1.Final-SNAPSHOT"
mcauthlib = "d9d773e" mcauthlib = "d9d773e"
mcprotocollib = "1.19.4-math2-SNAPSHOT" 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" adventure-platform = "4.1.2"
junit = "5.9.2" junit = "5.9.2"
checkerframework = "3.19.0" checkerframework = "3.19.0"