Added locale to api

This commit is contained in:
ile123ile 2014-08-31 17:08:18 -07:00
parent 4d4e3a2b47
commit db2128daeb
2 changed files with 34 additions and 3 deletions

View File

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

View File

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