使用 inner <span> 国际化元素

Internationalize element with inner <span>

我正在使用 Spring Boot + Thymeleaf。我想国际化这样的东西:

<p>Already registered? <span class="link">Log In</span></p>

如果我将 th:text="#{prompt}" 添加到 <p> 标签,内部 span 将被 属性 值替换。

有什么方法可以使 <p> 元素的整个 text 国际化,我的资源包中只有一个 属性 吗? (也许有占位符或者我不知道)

您可以在 属性 值

中为 html 标签添加占位符

属性:

prompt = Already registered? {0}Log In{1};

Html:

<p th:utext="#{prompt('<span class=link>', '</span>')}"></p>

注意:我使用 th:utext 而不是 th:text 因为它不会转义 html.

但如果您只拥有两个不同的属性,那就更清楚了。例如:

<p>
    <th:block th:text='#{prompt1}'></th:block>
    <span class='link' th:text='#{prompt2}'></span>
</p>