Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested property in ResourceBundleMessageSource

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.

like image 202
novice Avatar asked Nov 08 '22 22:11

novice


1 Answers

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
like image 81
aenigmatista Avatar answered Nov 14 '22 23:11

aenigmatista