1

I using thymeleaf and spring boot to build my web application.
I have problem on internationalization.
I need to change all text on my web application into outer file based (all text include validation).
I have code like this:

error.required=The {0} is required

My web application have 2 validation.
Validation from modal warning and validation from javascript for bootstrapvalidator.
For javascript, it work fine after I implement JavaScript equivalent to printf/string.format
But my problem is on thymeleaf.
My question: How do I inject {0} from (The {0} is required) with another string?

NB: I have tried to do something like this but the result is error

<p th:text="string.format(#{error.required}, #{label.name})"></p>
Community
  • 1
  • 1
Andri Handoko
  • 75
  • 1
  • 8
  • Are you trying to insert #{label.name} in {0} inside error.required? In that case, it should be: th:text="#{error.required(#{label.name})}" – Leandro Carracedo Jan 07 '15 at 13:55

1 Answers1

1

Using Thymeleaf to insert a property string inside another one defined with one or more parameters, the construction follows this format:

#{multiplestr.parameters(#{text.param1},#{text.param2})}

In this case, to insert #{label.name} in {0} inside the error.required text:

#{error.required(#{label.name})}

Messages in Thymeleaf

Leandro Carracedo
  • 7,233
  • 2
  • 44
  • 50