【发布时间】:2016-04-09 16:50:04
【问题描述】:
如果 Spring 可以自动解析嵌套属性,我需要帮助。我使用的是 Spring 4.2.4,Java 8,属性文件看起来像 -
# messages.properties
company.name=XYZ
welcome.message=Dear Customers of ${company.name}
about.company=${company.name} is blah blah
我们有一个自定义的本地化实现来从 i18 的资源包中获取字符串,如下定义-
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();
}
我希望能够使用 get(locale, "welcome.message") 之类的方法,并希望将其呈现为 XYZ 的亲爱的客户。
目前它在 MessageFormat 中无法正常工作。有没有办法让spring自动解决这个问题。
【问题讨论】:
标签: java spring-mvc internationalization