Thymeleaf不在某些语言环境中呈现消息内的变量 [英] Thymeleaf doesn't render variables within messages in some locales
问题描述
我的messages.properties
文件中有一个键的文本,其中包含变量:
I have a text for a key in my messages.properties
file with variables in it:
some.key=You'll need to pay {0} {1} in order to continue.
并且我的应用程序支持两种语言环境:messages.properties
表示英语,messages_tr.properties
表示土耳其语(默认为Locale
).
and I have it in both locales that my application supports: messages.properties
for English, and messages_tr.properties
for Turkish (the default Locale
).
因此,当我使用土耳其语区域设置呈现页面时,此方法有效:
So this works when I render the page with Turkish locale:
我得到:
Some Turkish words 10 USD some other Turkish words.
因此,{0} {1}
被替换为金额和货币.但是当我用英语呈现页面时却没有:
So, {0} {1}
gets replaced with the amount and currency. But it doesn't when I render the page in English:
You'll need to pay {0} {1} in order to continue.
我做错了什么?谢谢.
推荐答案
问题似乎出在单引号中.
Looks like the problem is in the single quote.
从此处:
单引号用于表示消息格式中将不格式化的部分.单引号本身必须通过使用两个单引号('')进行转义
The single quote is used to represent a section within the message pattern that will not be formatted. A single quote itself must be escaped by using two single quotes ('')
因此,您在messages.properties中的消息应为:
So your message in messages.properties should be:
You''ll need to pay {0} {1} in order to continue.
这篇关于Thymeleaf不在某些语言环境中呈现消息内的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!