Search code examples
springspring-mvcthymeleafspring-bean

Spring Boot Thymeleaf Internationalization


I am unable to implement internationalization on custom attributes (e.g HTML5 data attributes, data-tooltip) in Spring Boot Thymeleaf. Here is the sample code.

<a class="active" th:text="#{label.management}"></a>
...
<input type="text" th:field="*{username}" th:placeholder="#{label.username}" />
...
<div class="fixed-action-btn tooltipped" data-position="left" data-delay="50" th:data-tooltip="#{label.quicklinks}">
    <a class="btn-floating btn-large orange">
        <i class="large icons ion-edit"></i>
    </a>
    ....
</div>

They th:text and the th:placeholder are okay. But the th:data-tooltip prints an empty string.

I wish to find out how to implement Spring boot thymeleaf translation on custom HTML elements. Thanks.


Solution

  • This is an issue in Thymeleaf 2.x, see https://github.com/thymeleaf/thymeleaf/issues/489

    Either upgrade to 3.x or use the th:attr as a workaround. https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#setting-value-to-specific-attributes

    e.g.

    th:attr="data-tooltip=#{label.quicklinks}"/>