Refactor LocaleLoader a bit

This commit is contained in:
NuclearW 2013-02-06 01:05:09 -05:00
parent bbfbe1e72c
commit c13593def1
2 changed files with 31 additions and 19 deletions

View File

@ -10,8 +10,8 @@ import org.bukkit.ChatColor;
import com.gmail.nossr50.config.Config;
public final class LocaleLoader {
private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale";
private static ResourceBundle RESOURCE_BUNDLE = null;
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
private static ResourceBundle bundle = null;
private LocaleLoader() {};
@ -27,23 +27,12 @@ public final class LocaleLoader {
* @return The properly formatted locale string
*/
public static String getString(String key, Object ... messageArguments) {
if (bundle == null) {
initialize();
}
try {
if (RESOURCE_BUNDLE == null) {
Locale.setDefault(new Locale("en", "US"));
Locale locale = null;
String[] myLocale = Config.getInstance().getLocale().split("[-_ ]");
if (myLocale.length == 1) {
locale = new Locale(myLocale[0]);
}
else if (myLocale.length >= 2) {
locale = new Locale(myLocale[0], myLocale[1]);
}
RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, locale);
}
String output = RESOURCE_BUNDLE.getString(key);
String output = bundle.getString(key);
if (messageArguments != null) {
MessageFormat formatter = new MessageFormat("");
@ -60,6 +49,30 @@ public final class LocaleLoader {
}
}
public static Locale getCurrentLocale() {
if (bundle == null) {
initialize();
}
return bundle.getLocale();
}
private static void initialize() {
if (bundle == null) {
Locale.setDefault(new Locale("en", "US"));
Locale locale = null;
String[] myLocale = Config.getInstance().getLocale().split("[-_ ]");
if (myLocale.length == 1) {
locale = new Locale(myLocale[0]);
}
else if (myLocale.length >= 2) {
locale = new Locale(myLocale[0], myLocale[1]);
}
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
}
}
private static String addColors(String input) {
input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString());
input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString());

View File

@ -564,4 +564,3 @@ public class mcMMO extends JavaPlugin {
xpEventEnabled = !xpEventEnabled;
}
}