|
@@ -1,12 +1,21 @@
|
|
|
package pl.sudra.configuration;
|
|
package pl.sudra.configuration;
|
|
|
|
|
|
|
|
|
|
+import org.springframework.context.MessageSource;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
import org.springframework.context.annotation.ComponentScan;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
|
|
|
|
+import org.springframework.web.servlet.LocaleResolver;
|
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
|
|
|
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
+import org.springframework.web.servlet.i18n.CookieLocaleResolver;
|
|
|
|
|
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
|
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
|
|
|
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
+import java.util.Locale;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
|
@EnableWebMvc
|
|
@EnableWebMvc
|
|
@@ -19,4 +28,27 @@ public class SpringConfiguration implements WebMvcConfigurer {
|
|
|
viewResolver.setSuffix(".jsp");
|
|
viewResolver.setSuffix(".jsp");
|
|
|
return viewResolver;
|
|
return viewResolver;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public MessageSource messageSource() {
|
|
|
|
|
+ ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
|
|
|
|
+ messageSource.setBasename("/resources/i18n/messages");
|
|
|
|
|
+ messageSource.setDefaultEncoding("UTF-8");
|
|
|
|
|
+ return messageSource;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public LocaleResolver localeResolver() {
|
|
|
|
|
+ CookieLocaleResolver resolver = new CookieLocaleResolver("myLocaleCookie");
|
|
|
|
|
+ resolver.setDefaultLocale(new Locale("en"));
|
|
|
|
|
+ resolver.setCookieMaxAge(Duration.ofSeconds(4800));
|
|
|
|
|
+ return resolver;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
|
+ LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
|
|
|
|
|
+ interceptor.setParamName("lang");
|
|
|
|
|
+ registry.addInterceptor(interceptor);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|