mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Allow Minecraft locales to be loaded even if offline
This commit is contained in:
parent
5e1769d2bd
commit
5b67c78785
1 changed files with 13 additions and 6 deletions
|
@ -126,14 +126,20 @@ public class MinecraftLocale {
|
||||||
|
|
||||||
// Check the locale isn't already loaded
|
// Check the locale isn't already loaded
|
||||||
if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
|
if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
|
||||||
|
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));
|
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.locale.fail.invalid", locale));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GeyserImpl.getInstance().getLogger().debug("Downloading and loading locale: " + locale);
|
GeyserImpl.getInstance().getLogger().debug("Downloading and loading locale: " + locale);
|
||||||
|
|
||||||
downloadLocale(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
|
* @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();
|
File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
||||||
|
|
||||||
// Load the locale
|
// Load the locale
|
||||||
|
@ -242,8 +248,9 @@ public class MinecraftLocale {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new AssertionError(GeyserLocale.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage()));
|
throw new AssertionError(GeyserLocale.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage()));
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
} else {
|
} 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
|
* @return Translated string or the original message if it was not found in the given locale
|
||||||
*/
|
*/
|
||||||
public static String getLocaleString(String messageText, String 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) {
|
if (localeStrings == null) {
|
||||||
localeStrings = MinecraftLocale.LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale());
|
localeStrings = LOCALE_MAPPINGS.get(GeyserLocale.getDefaultLocale());
|
||||||
if (localeStrings == null) {
|
if (localeStrings == null) {
|
||||||
// Don't cause a NPE if the locale is STILL missing
|
// Don't cause a NPE if the locale is STILL missing
|
||||||
GeyserImpl.getInstance().getLogger().debug("MISSING DEFAULT LOCALE: " + GeyserLocale.getDefaultLocale());
|
GeyserImpl.getInstance().getLogger().debug("MISSING DEFAULT LOCALE: " + GeyserLocale.getDefaultLocale());
|
||||||
|
|
Loading…
Reference in a new issue