Thymeleaf 获取当前语言环境 [英] Thymeleaf get current locale
本文介绍了Thymeleaf 获取当前语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 thymeleaf 模板中获取当前语言环境?Thymeleaf 上下文是语言环境感知的,所以在每个请求中注入语言环境会很奇怪,我可以在模板中请求一些变量吗?
解决方案
使用 #locale 表达式:
How can I get current locale in thymeleaf template? Thymeleaf context is locale aware, so it would be weird to inject locale on every request, is there some variable I can request in a template?
<div th:text="${currentLocale}"></div>
解决方案
Use the #locale expression:
<div th:text="${#locale}"></div>
这篇关于Thymeleaf 获取当前语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文