diff --git a/src/main/java/com/gmail/nossr50/api/LocaleAPI.java b/src/main/java/com/gmail/nossr50/api/LocaleAPI.java new file mode 100644 index 000000000..c6c6268e2 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/LocaleAPI.java @@ -0,0 +1,22 @@ +package com.gmail.nossr50.api; + +import java.util.ResourceBundle; + +import com.gmail.nossr50.locale.LocaleLoader; + +public final class LocaleAPI { + + public static void addBundles(ResourceBundle bundle, ResourceBundle defaultBundle) { + LocaleLoader.addResourceBundle(bundle, defaultBundle); + } + + public static void addBundle(ResourceBundle bundle, boolean isDefault) { + if(isDefault) { + addBundles(null, bundle); + } + else { + addBundles(bundle, null); + } + } + +} diff --git a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java index 1258ccd77..2e083d58d 100644 --- a/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java +++ b/src/main/java/com/gmail/nossr50/locale/LocaleLoader.java @@ -89,14 +89,14 @@ public final class LocaleLoader { private static void initialize() { if (bundle == null) { - Locale locale = getLocalFromConfig(); + Locale locale = getLocaleFromConfig(); bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale); enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US); } } - private static Locale getLocalFromConfig() { + public static Locale getLocaleFromConfig() { Locale.setDefault(new Locale("en", "US")); Locale locale = null; String[] myLocale = Config.getInstance().getLocale().split("[-_ ]"); @@ -111,10 +111,19 @@ public final class LocaleLoader { } public static void addResourceBundle(String bundleRoot, Locale defaultLocale) { - Locale locale = getLocalFromConfig(); + Locale locale = getLocaleFromConfig(); bundles.add(ResourceBundle.getBundle(bundleRoot, locale)); defaultBundles.add(ResourceBundle.getBundle(bundleRoot, defaultLocale)); } + + public static void addResourceBundle(ResourceBundle bundle, ResourceBundle defaultBundle) { + if(bundle != null) { + bundles.add(bundle); + } + if(defaultBundle != null) { + defaultBundles.add(defaultBundle); + } + } private static String addColors(String input) { input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString());