3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Allow Minecraft locales to be loaded even if offline

Dieser Commit ist enthalten in:
Camotoy 2022-06-16 17:14:47 -04:00
Ursprung 5e1769d2bd
Commit 5b67c78785
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F

Datei anzeigen

@ -126,14 +126,20 @@ public class MinecraftLocale {
// Check the locale isn't already loaded
if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.invalid", locale));
if (loadLocale(locale)) {
GeyserImpl.getInstance().getLogger().debug("Loaded locale locally while not being in asset map: " + locale);
} else {
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.invalid", locale));
}
return;
}
GeyserImpl.getInstance().getLogger().debug("Downloading and loading locale: " + locale);
downloadLocale(locale);
loadLocale(locale);
if (!loadLocale(locale)) {
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.missing", locale));
}
}
/**
@ -199,7 +205,7 @@ public class MinecraftLocale {
*
* @param locale Locale to load
*/
private static void loadLocale(String locale) {
private static boolean loadLocale(String locale) {
File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
// Load the locale
@ -242,8 +248,9 @@ public class MinecraftLocale {
} catch (IOException e) {
throw new AssertionError(GeyserLocale.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage()));
}
return true;
} else {
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.missing", locale));
return false;
}
}
@ -300,9 +307,9 @@ public class MinecraftLocale {
* @return Translated string or the original message if it was not found in the given locale
*/
public static String getLocaleString(String messageText, String locale) {
Map<String, String> localeStrings = MinecraftLocale.LOCALE_MAPPINGS.get(locale.toLowerCase());
Map<String, String> localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase(Locale.ROOT));
if (localeStrings == null) {
localeStrings = MinecraftLocale.LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale());
localeStrings = LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale());
if (localeStrings == null) {
// Don't cause a NPE if the locale is STILL missing
GeyserImpl.getInstance().getLogger().debug("MISSING DEFAULT LOCALE: " + GeyserLocale.getDefaultLocale());