我想使用ResourceBundleMessageSource实现以下行为:
在下面有文件,我想呈现Dear Customer of MyCompany
消息。
# messages.properties
company.name=MyCompany
welcomeMessage.beginning=Dear Customers of ${company.name}
是否有可能以某种方式嵌套一个标签的键,其值不同?
答案 0 :(得分:-1)
是的,解析任意对象是MessageSource接口的一部分。因此,要解析普通的消息代码,您只需将其封装在DefaultMessageSourceResolvable中,如:
messageSource.getMessage("welcomeMessage.beginning",
new Object[]{new DefaultMessageSourceResolvable("company.name")},
locale);
您不需要花哨的消息格式(标准MessageFormat也不允许),只需使用:
# messages.properties
company.name=MyCompany
welcomeMessage.beginning=Dear Customers of {0}