I am writing a spring boot application using Thymeleaf as template engine.
My web app has English and Ukrainian locales.
The issue is that Month of dates is ALWAYS localized to UA (Ukrainian) locale: i.e. 11-травня-2020
If I change locale to English using language picker the date is still the same (11-травня-2020), provided that other parts are translated.
If I try to use new java.util.Locale('en', 'EN') then 11-May-2020 date is displayed (as expected).
HTML part where I use my dates in the table:
<table class="table table-bordered table-striped ">
<thead class="thead-dark">
<tr>
...
<th></th>
</tr>
</thead>
<tbody>
<tr th:each="tempReport : ${page}">
...
<td th:text="${#temporals.format(T(java.time.LocalDate).of(#dates.year(tempReport.reportDate),
#dates.month(tempReport.reportDate), #dates.day(tempReport.reportDate)),
'dd-MMMM-yyyy', new java.util.Locale('uk', 'UA'))}"
></td>
</tr>
</tbody>
</table>
My locale configuration:
@Configuration
public class Localization implements WebMvcConfigurer {
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver resolver = new SessionLocaleResolver();
resolver.setDefaultLocale(Locale.ENGLISH);
return resolver;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("lang");
return interceptor;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
}
My Language picker:
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item dropdown active ml-5">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
th:text="${#strings.toUpperCase(#locale)}">
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" th:href="@{?lang=en}" th:text="#{navigation.eng}"></a>
<a class="dropdown-item" th:href="@{?lang=ua}" th:text="#{navigation.ua}"></a>
</div>
</li>
</ul>
</div>
Any help to resolve the issue will be appreciated!