diff --git a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java index 9ad19be..9716493 100644 --- a/src/main/java/ru/ulstu/configuration/MvcConfiguration.java +++ b/src/main/java/ru/ulstu/configuration/MvcConfiguration.java @@ -6,10 +6,15 @@ package ru.ulstu.configuration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.i18n.CookieLocaleResolver; +import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; @Configuration public class MvcConfiguration implements WebMvcConfigurer { @@ -24,4 +29,21 @@ public class MvcConfiguration implements WebMvcConfigurer { .addResourceHandler("/webjars/**") .addResourceLocations("/webjars/"); } + + @Bean + public LocaleResolver localeResolver() { + return new CookieLocaleResolver(); + } + + @Bean + public LocaleChangeInterceptor localeInterceptor() { + LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); + localeInterceptor.setParamName("lang"); + return localeInterceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(localeInterceptor()); + } }