Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

thymeleaf internationalization use default text html

I'm using thymeleaf with Spring Boot,

<span th:text="#{home.welcome}">Welcome Default Message</span>

When key is not found in messages.properties, I had

??home.welcome_en_US??

I dont want to translate every message in messages.properties. I would like to have "Welcome Default Message" writed in html page when translate key message is not found.

How I can do that?

like image 601
Thibaut Avatar asked Jul 29 '26 01:07

Thibaut


1 Answers

Maybe not relevant anymore, but the following worked for me. I am running Thymeleaf 3.0.7.RELEASE.

<span th:text="${#strings.defaultString(#messages.msgOrNull('home.welcome'),'Welcome Default Message')}"/>

If message is not found, null is passed to the #strings.defaultString call which when given null parameter will return 'Welcome Default Message'.

More here http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#strings

like image 116
Tanya Kogan Avatar answered Jul 30 '26 14:07

Tanya Kogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!