Thymeleaf get current locale from request or session

Viewed 905

How can I get current locale in thymeleaf template ?

I've tried

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

and

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

but none of both works

1 Answers

Try

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

There are quite a lot of attributes like these, each of them targeting a specific XHTML or HTML5 attribute.

Related