编写Spring Resource Boundle时是否有单一规则来处理单引号?

tar*_*ini 11 java spring resourcebundle internationalization double-quotes

Spring的ResourceBundleMessageSource使用MessageFormat替换占位符({0})内的信息.

MessageFormat要求'使用两个单引号('')转义单引号()(请参阅:MessageFormat Javadoc).但是,默认情况下,不会解析不包含任何参数的MessageFormat消息,因此不需要对不带参数的消息中的单引号进行转义.

因此,您的翻译人员必须了解编写和维护资源包的两个规则:

  • write('')如果带有单引号的消息也包含至少一个占位符({0});
  • '如果带有单引号的消息不包含占位符,则使用write().

编写Spring Resource Boundle时是否有单一规则来处理单引号?

tar*_*ini 10

ResourceBundleMessageSource提供了一个标志alwaysUseMessageFormat,如果MessageFormat应该应用于所有消息,则可以使用该标志.

单一规则是......

为您的所有资源边界配置一次:

<bean 
    id="messageSource" 
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="alwaysUseMessageFormat" value="true" />
    ...
</bean>
Run Code Online (Sandbox Code Playgroud)

并且您的翻译人员必须了解编写和维护资源包的单一规则:

  • 写总是('')

另请参见为什么在某些语言环境中未正确填充Spring MessageSource参数.