I have a traditional Spring4/Thymeleaf i18n application I switch the locale easily with classic
org.springframework.web.servlet.i18n.LocaleChangeInterceptor
and
org.springframework.web.servlet.i18n.CookieLocaleResolver
When switching I always send to the server /home?lang=fr. It works fine. But I need a more complex behaviour. What I need to do is to preserve the current page while switching the locale.
I found a half-working solution with this thymeleaf snippet:
th:with="currentUrl=(${#httpServletRequest.pathInfo + '?' + #strings.defaultString(#httpServletRequest.queryString, '')})
The problem is I need to implement myself many corner cases:
- when there is already any query parameter
- if there is a lang=en param,
- etc.
Does anybody know how to manage this case with native Spring or Thymeleaf tools? Or I need to write my own processor for Thymeleaf?