Refactor localized message helper method

This commit is contained in:
davioooh 2018-04-30 19:50:44 +02:00 committed by Abbas Abou Daya
parent 97a4c0031b
commit 7ff5be3a72
2 changed files with 6 additions and 3 deletions

View File

@ -181,12 +181,15 @@ public final class AbilityUtils {
public static String getLocalizedMessage(String messageCode, Locale locale, Object...arguments) {
ResourceBundle bundle;
if(locale == null){
bundle = ResourceBundle.getBundle("default_messages");
bundle = ResourceBundle.getBundle("messages", Locale.ROOT);
}else {
try {
bundle = ResourceBundle.getBundle("messages", locale);
bundle = ResourceBundle.getBundle(
"messages",
locale,
ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES));
} catch (MissingResourceException e) {
bundle = ResourceBundle.getBundle("default_messages");
bundle = ResourceBundle.getBundle("messages", Locale.ROOT);
}
}
String message = bundle.getString(messageCode);