【问题标题】:Thymeleaf doesn't render variables within messages in some locales在某些语言环境中,Thymeleaf 不会在消息中呈现变量
【发布时间】:2019-01-11 11:54:18
【问题描述】:

我的 messages.properties 文件中有一个键文本,其中包含变量:

some.key=You'll need to pay {0} {1} in order to continue.

我的应用程序支持的两种语言环境都有它:messages.properties 用于英语,messages_tr.properties 用于土耳其语(默认 Locale)。

所以当我使用土耳其语言环境渲染页面时,这可以工作:

我得到:

Some Turkish words 10 USD some other Turkish words.

因此,{0} {1} 被替换为金额和货币。但是当我用英文呈现页面时它不会:

You'll need to pay {0} {1} in order to continue.

我做错了什么?谢谢。

【问题讨论】:

    标签: spring spring-boot thymeleaf locale


    【解决方案1】:

    看起来问题出在单引号中。

    来自here

    单引号用于表示消息模式中不会被格式化的部分。单引号本身必须使用两个单引号 ('') 进行转义

    所以你在 messages.properties 中的信息应该是:

    You''ll need to pay {0} {1} in order to continue.

    【讨论】:

    • 谢谢,这正是发生的事情。
    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-21
    相关资源
    最近更新 更多