Thymeleaf doesn't render variables within messages in some locales

倖福魔咒の 提交于 2019-12-20 07:16:28

问题


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.

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:

and I get:

Some Turkish words 10 USD some other Turkish words.

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.

What am I doing wrong? Thanks.


回答1:


Looks like the problem is in the single quote.

From here:

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 ('')

So your message in messages.properties should be:

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



来源:https://stackoverflow.com/questions/51675147/thymeleaf-doesnt-render-variables-within-messages-in-some-locales

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!