Why Spring MessageSource arguments are not filled correctly in some locales?

后端 未结 4 1492
陌清茗
陌清茗 2020-12-29 03:05
mailconfirm.mail.body=

Hi, {0}!

\\ To confirm your email address click on the confirmation
4条回答
  •  無奈伤痛
    2020-12-29 03:32

    Spring's ResourceBundleMessageSource (which I think you are using) uses MessageFormat for replacing placeholders ({0}) inside messages. MessageFormat requires that single quotes (') are escaped using two single quotes ('') (see: MessageFormat Javadoc).

    However, by default messages that do not contain any arguments will not be parsed by MessageFormat. So single quotes in messages without arguments don't need to be escaped.

    ResourceBundleMessageSource provides a flag called alwaysUseMessageFormat that can be used if MessageFormat should be applied to all messages. So a single quote need always be escaped by two single quotes.

    See this blog post for more details.

提交回复
热议问题