【问题标题】:Thymeleaf get current locale from request or sessionThymeleaf 从请求或会话中获取当前语言环境
【发布时间】:2021-01-01 06:43:55
【问题描述】:

如何在 thymeleaf 模板中获取当前语言环境?

我试过了

<html xmlns:th="http://www.thymeleaf.org" lang="${#locale}" xml:lang="${#locale}" class="no-js">

<html xmlns:th="http://www.thymeleaf.org" lang="${request.locale}" xml:lang="${request.locale}" class="no-js"> 

但两者都不起作用

【问题讨论】:

  • Locale 是一个对象 - 所以你必须指定你想要的属性 - 例如:th:lang="${#locale.language}"th:country="${#locale.country}"

标签: java html spring spring-boot thymeleaf


【解决方案1】:

试试

<html xmlns:th="http://www.thymeleaf.org"
      th:lang="${#locale.language}" 
      th:xmllang="${#locale.language}" 
      class="no-js">

有很多类似的属性,每个属性都针对特定的XHTML or HTML5 attribute

【讨论】:

    猜你喜欢
    • 2017-04-11
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 2016-07-13
    相关资源
    最近更新 更多