代码之家  ›  专栏  ›  技术社区  ›  Mahozad

将内部元素国际化

  •  -1
  • Mahozad  · 技术社区  · 7 年前

    我在和春靴+百里香一起工作。我想把这样的东西国际化:

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

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

    有什么办法使整个国家国际化吗 文本 属于 <P & GT; 我的资源包中只有一个属性的元素?(可能是有占位符,或者我不知道)

    1 回复  |  直到 7 年前
        1
  •  1
  •   Alexandru Severin    7 年前

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