(th:text)Message(i18n)表达式与其他文本的连续性

时间:2018-04-20 23:42:28

标签: thymeleaf

我正在使用:

  • Thymeleaf 3.0.9.RELEASE
  • Spring Framework

关于i18n以下工作正常(在任何html组件中):

th:text="#{person.name.label}"

person.name.label密钥存在于.properties文件中,并且根据Locale值,例如Name已打印。

我现在需要打印而不是Name:。观察:,例如用于<label>

如果我尝试:

th:text="#{person.name.label}:"

我得到了

org.thymeleaf.exceptions.TemplateProcessingException: 
Could not parse as expression: "#{persona.name.label}:"

如果我尝试

th:text="#{person.name.label:}"

而是打印??persona.name.label:_en_US??

我不希望在:文件中直接添加.properties,因为我想在person.name.label内的<th>中使用<thead>,因此没必要打印:

正确的方法是什么?。

1 个答案:

答案 0 :(得分:1)

Standard syntax for appending text.

th:text="#{person.name.label} + ':'"

Or, you may be interested in literal substitution.

th:text="|#{person.name.label}:|"

You can also accomplish these kinds of expressions with inlining.这在Thymeleaf 3中默认启用,表达式如下所示。

<span>[[#{person.name.label}]]:</span>

在Thymeleaf 2中,您必须通过添加th:inline来启用此功能,如下所示:

<span th:inline="text">[[#{person.name.label}]]:</span>