From c2d4aeaf8509fa06e3c9101fee28e71136b2b027 Mon Sep 17 00:00:00 2001 From: Mark Vainomaa Date: Mon, 29 Apr 2019 01:25:00 +0300 Subject: [PATCH] Try to load locale from plugin data folder first --- .../gmail/nossr50/locale/LocaleLoader.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java index c48fd66bc..b5b65d928 100644 --- a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java +++ b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java @@ -4,10 +4,17 @@ import com.gmail.nossr50.config.Config; import com.gmail.nossr50.mcMMO; import org.bukkit.ChatColor; +import java.io.IOException; +import java.io.Reader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; +import java.util.PropertyResourceBundle; import java.util.ResourceBundle; +import java.util.logging.Level; public final class LocaleLoader { private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale"; @@ -85,7 +92,21 @@ public final class LocaleLoader { locale = new Locale(myLocale[0], myLocale[1]); } - bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale); + if (locale == null) { + throw new IllegalStateException("Failed to parse locale string '" + Config.getInstance().getLocale() + "'"); + } + + Path localePath = Paths.get(mcMMO.getMainDirectory() + "locale_" + locale.toString() + ".properties"); + if (Files.exists(localePath) && Files.isRegularFile(localePath)) { + try (Reader localeReader = Files.newBufferedReader(localePath)) { + bundle = new PropertyResourceBundle(localeReader); + } catch (IOException e) { + mcMMO.p.getLogger().log(Level.WARNING, "Failed to load locale from " + localePath, e); + bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale); + } + } else { + bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale); + } enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US); } }