I wanted help if its possible to auto resolve by Spring the nested property. I am using Spring 4.2.4, Java 8 and the property file looks like-
# messages.properties
company.name=XYZ
welcome.message=Dear Customers of ${company.name}
about.company=${company.name} is blah blah
We have a custom localization implementation to get the String from Resource bundle for i18 as defined below-
public String get(Locale locale, String key, Object... arguments) {
String pattern = this.getString(locale, key);
MessageFormat formatter = new MessageFormat(pattern, locale);
StringBuffer buffer = new StringBuffer();
formatter.format(arguments, buffer, null);
return buffer.toString();
}
I want to be able to use this method like get(locale, "welcome.message") and expect to render it as Dear Customers of XYZ.
Currently its not working failing in MessageFormat. Is there a way to allow spring auto resolve this.
You can now use curly braces (without symbol $). It work for Spring 5 (tested for 5.3.6 and 5.3.7):
# messages.properties
company.name=XYZ
welcome.message=Dear Customers of {company.name}
about.company={company.name} is blah blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With