Fall back to locale loaded from JAR when filesystem one doesn't have requested key

This commit is contained in:
Mark Vainomaa 2019-04-29 20:58:54 +03:00
parent c2d4aeaf85
commit 0f2e1ea740

View File

@ -19,6 +19,7 @@ import java.util.logging.Level;
public final class LocaleLoader {
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
private static ResourceBundle bundle = null;
private static ResourceBundle filesystemBundle = null;
private static ResourceBundle enBundle = null;
private LocaleLoader() {};
@ -39,6 +40,13 @@ public final class LocaleLoader {
initialize();
}
if (filesystemBundle != null) {
try {
return getString(key, filesystemBundle, messageArguments);
}
catch (MissingResourceException ignored) {}
}
try {
return getString(key, bundle, messageArguments);
}
@ -99,14 +107,12 @@ public final class LocaleLoader {
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);
filesystemBundle = 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);
}
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
}
}