package
com.demo.config;
import
org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration;
import
org.springframework.context.support.ResourceBundleMessageSource;
import
org.springframework.web.servlet.LocaleResolver;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry;
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
WebConfig
implements
WebMvcConfigurer {
@Bean
public
LocaleResolver localeResolver()
{
return
new
CookieLocaleResolver();
}
@Bean
public
LocaleChangeInterceptor localeChangeInterceptor()
{
LocaleChangeInterceptor localeChangeInterceptor
=
new
LocaleChangeInterceptor();
localeChangeInterceptor.setParamName(
"lang"
);
return
localeChangeInterceptor;
}
@Bean
public
ResourceBundleMessageSource messageSource()
{
ResourceBundleMessageSource messageSource
=
new
ResourceBundleMessageSource();
messageSource.setBasename(
"messages/messages"
);
messageSource.setDefaultEncoding(
"UTF-8"
);
return
messageSource;
}
@Override
public
void
addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(localeChangeInterceptor());
}
}