[New] Added I18nMessage.formatMessage(ResourceBundle)
This commit is contained in:
parent
60fdb34150
commit
50dbd1359a
|
@ -49,6 +49,10 @@ public class I18nMessage {
|
||||||
return this.values.get(key);
|
return this.values.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMessage(ResourceBundle bundle) {
|
||||||
|
return formatMessage(bundle);
|
||||||
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return formatMessage();
|
return formatMessage();
|
||||||
}
|
}
|
||||||
|
@ -68,17 +72,22 @@ public class I18nMessage {
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
this.message = formatMessage(this.bundle);
|
||||||
String string = this.bundle.getString(this.key);
|
|
||||||
this.message = StringHelper.replacePropertiesIn(this.values, EMPTY, string);
|
|
||||||
} catch (MissingResourceException e) {
|
|
||||||
logger.error("Key " + this.key + " is missing in bundle " + this.bundle.getBaseBundleName());
|
|
||||||
this.message = this.key;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String formatMessage(ResourceBundle bundle) {
|
||||||
|
try {
|
||||||
|
String string = bundle.getString(this.key);
|
||||||
|
return StringHelper.replacePropertiesIn(this.values, EMPTY, string);
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
String baseName = bundle.getBaseBundleName();
|
||||||
|
String languageTag = bundle.getLocale().toLanguageTag();
|
||||||
|
logger.error("Key " + this.key + " is missing in bundle " + baseName + " for locale " + languageTag);
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public <T> T accept(I18nMessageVisitor<T> visitor) {
|
public <T> T accept(I18nMessageVisitor<T> visitor) {
|
||||||
return visitor.visit(this);
|
return visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue