Locale fallback

This commit is contained in:
NuclearW 2013-02-14 23:27:03 -05:00
parent caa1b0d14c
commit 092b9096e6

View File

@ -12,6 +12,7 @@ import com.gmail.nossr50.config.Config;
public final class LocaleLoader {
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
private static ResourceBundle bundle = null;
private static ResourceBundle enBundle = null;
private LocaleLoader() {};
@ -32,6 +33,19 @@ public final class LocaleLoader {
}
try {
return getString(key, bundle, messageArguments);
}
catch (MissingResourceException ex) {
try {
return getString(key, enBundle, messageArguments);
}
catch (MissingResourceException ex2) {
return '!' + key + '!';
}
}
}
private static String getString(String key, ResourceBundle bundle, Object ... messageArguments) throws MissingResourceException {
String output = bundle.getString(key);
if (messageArguments != null) {
@ -44,10 +58,6 @@ public final class LocaleLoader {
return output;
}
catch (MissingResourceException e) {
return '!' + key + '!';
}
}
public static Locale getCurrentLocale() {
if (bundle == null) {
@ -70,6 +80,7 @@ public final class LocaleLoader {
}
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
}
}