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); } }