简体   繁体   中英

String Format Thymeleaf Spring Boot

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM