【发布时间】: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