本文介绍了在编写Spring Resource Boundle时,是否有一条规则可以处理单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Spring's ResourceBundleMessageSource uses MessageFormat for replacing placeholders ({0}) inside messages.

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

MessageFormat requires that single quotes (') are escaped using two single quotes ('') (see: MessageFormat Javadoc). However, by default messages that does not contain any arguments will not be parsed by MessageFormat, so single quotes in messages without arguments don't need to be escaped.

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

So your translator have to be aware of two rules in writing and maintaining resource bundle:

    如果带有单引号的邮件也至少包含一个占位符({0}),请
  • 写('');
  • 如果带有单引号的邮件不包含任何占位符,请
  • 写(').
  • write ('') if the message with the single quotes contains at least one placeholders ({0}) too;
  • write (') if the message with the single quotes contains none placeholders.

在编写Spring Resource Boundle时,是否有一条规则可以处理单引号?

Is there a single rule to cope with single quotes in writing Spring Resource Boundle?

推荐答案

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

ResourceBundleMessageSource provides a flag called alwaysUseMessageFormat that can be used if MessageFormat should be applied to all messages.

为所有资源限制配置一次:

Configure one time for all your resource boundle with:

<bean
    id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="alwaysUseMessageFormat" value="true" />
    ...
</bean>

您的翻译人员在编写和维护资源包时必须了解一个规则:

and your translator have to be aware of a single rule in writing and maintaining resource bundle:

  • 始终写入('')

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

这篇关于在编写Spring Resource Boundle时,是否有一条规则可以处理单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-25 11:37