Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 553
Hoffmann Avatar asked Dec 26 '13 18:12

Hoffmann


People also ask

How do you display the list of objects in Thymeleaf?

First, we used the th:object=”${form}” to specify the command object (the one we passed as a Model attribute). And finally, we're mapping our inputs as properties of the list elements using th:field.

What is #{} in Thymeleaf?

Variable expressions are OGNL expressions –or Spring EL if you're integrating Thymeleaf with Spring. *{} is used for selection expressions. Selection expressions are just like variable expressions, except they will be executed on a previously selected object. #{} is used for message (i18n) expressions.

What is Thymeleaf spring5?

Thymeleaf is a Java template engine for processing and creating HTML, XML, JavaScript, CSS and text.


1 Answers

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.

like image 170
Sotirios Delimanolis Avatar answered Sep 22 '22 07:09

Sotirios Delimanolis