Spring 的 ResourceBundleMessageSource
使用 MessageFormat
替换消息中的占位符 ({0}
)。
MessageFormat
要求使用两个单引号 (''
) 对单引号 ('
) 进行转义(参见:MessageFormat Javadoc)。但是,默认情况下,不包含任何参数的消息不会被 MessageFormat
解析,因此没有参数的消息中的单引号不需要转义。
因此,您的翻译人员在编写和维护资源包时必须了解两条规则:
- 如果带有单引号的消息也包含至少一个占位符 (
{0}
),则写入 (''
); - 如果带有单引号的消息不包含占位符,则写入 (
'
)。
在编写Spring Resource Boundle时是否有一个单一的规则来处理单引号?
最佳答案
ResourceBundleMessageSource
提供了一个名为 alwaysUseMessageFormat
的标志,如果应该将 MessageFormat
应用于所有消息,则可以使用该标志。
单一规则是...
一次性为所有资源绑定(bind)配置:
<bean
id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="alwaysUseMessageFormat" value="true" />
...
</bean>
您的翻译人员在编写和维护资源包时必须了解一条规则:
- 总是写(
''
)
另见 Why Spring MessageSource arguments are not filled correctly in some locales .
关于java - 在编写 Spring Resource Bundle 时是否有一条规则来处理单引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22380243/