【问题标题】:Internationalize element with inner <span>使用内部 <span> 国际化元素
【发布时间】:2018-12-16 13:43:54
【问题描述】:

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

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

如果我将th:text="#{prompt}" 添加到&lt;p&gt; 标记中,则内部span 将被属性值替换。

有没有什么方法可以通过我的资源包中的一个属性来国际化&lt;p&gt; 元素的整个文本? (可能有占位符或者我不知道)

【问题讨论】:

    标签: spring spring-boot internationalization thymeleaf properties-file


    【解决方案1】:

    您可以在属性值内为 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>
    

    【讨论】:

    • 你确定('&lt;span class=link&gt;', '&lt;/span&gt;') 应该在} 之后吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多