1

My context path is / and I'm adding locales directly as part of the path: /de/index.html.

Now I'm facing the problem that th:href="@{/login.html}" will resolve to /login.html instead of /de/login.html.

I already tried making a Filter and an Interceptor like they did it here: https://stackoverflow.com/a/23847484/1163457

But it still won't append de/ after the context path.

Writing my own dialect and attribute processors would be a solution, but isn't there any better one?

Community
  • 1
  • 1
dtrunk
  • 4,685
  • 17
  • 65
  • 109

2 Answers2

1

Why not expose a model attribute for the locale (e.g. curLocale) and redefine all your urls like

th:href="@{/${curLocale}/login.html}"

Thymeleaf allows other expressions inside url expressions themselves. Locale information is easily accessible either as a method parameter or by calling RequestContext.getLocale()

gregdim
  • 2,031
  • 13
  • 15
  • That seems to be the only way without writing my own dialect. But I don't want to put the locale in every link. So this is not an option for me. – dtrunk Oct 29 '14 at 16:59
0

I found a clean and good solution myself after hours of step debugging: https://stackoverflow.com/a/60103777/1163457

dtrunk
  • 4,685
  • 17
  • 65
  • 109