Browse Source

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

Mark Vainomaa 6 năm trước cách đây
mục cha
commit
0f2e1ea740
1 tập tin đã thay đổi với 10 bổ sung4 xóa
  1. 10 4
      src/main/java/com/gmail/nossr50/locale/LocaleLoader.java

+ 10 - 4
src/main/java/com/gmail/nossr50/locale/LocaleLoader.java

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