小编nov*_*ice的帖子

ResourceBundleMessageSource 中的嵌套属性

如果可以通过 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
Run Code Online (Sandbox Code Playgroud)

我们有一个自定义的本地化实现来从 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();
}
Run Code Online (Sandbox Code Playgroud)

我希望能够像 get(locale, "welcome.message") 一样使用这种方法,并希望将其呈现为 XYZ 的尊敬的客户。

目前它在 MessageFormat 中无法正常工作。有没有办法让 spring 自动解决这个问题。

java spring-mvc internationalization

5
推荐指数
1
解决办法
610
查看次数

标签 统计

internationalization ×1

java ×1

spring-mvc ×1