How to show localization messages with parameters in Spring 3 / Thymeleaf

Hoffmann picture Hoffmann · Dec 26, 2013 · Viewed 31.5k times · Source

I'm using Spring 3 and Thymeleaf to make some webpages and I am lost as for how to show messages like this:

welcome.message=Hello {0}, welcome!

and then replace {0} with the user name inside thymeleaf tags:

<h1 th:text="#{welcome.message}">Welcome Placeholder</h1>

I'm not even sure if {0} is the right syntax for the bundle message.

Answer

Sotirios Delimanolis picture Sotirios Delimanolis · Dec 26, 2013

You can use

#{welcome.message(${some.attribute})}

where some.attribute would be the value to use when replacing {0}.

You should be able to comma separate the values between the () to add more values to be used.