package me.hao0.antares.tower.config; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ReloadableResourceBundleMessageSource; import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.i18n.CookieLocaleResolver; import java.util.Locale; /** * Author: haolin * Email: haolin.h0@gmail.com */ @Configuration public class I18nConfig { @Bean public LocaleResolver localeResolver(){ CookieLocaleResolver resolver = new CookieLocaleResolver(); resolver.setDefaultLocale(Locale.ENGLISH); return resolver; } @Bean public MessageSource messageSource(){ ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource(); messageSource.setBasename("classpath:i18n/messages"); messageSource.setDefaultEncoding("UTF-8"); messageSource.setUseCodeAsDefaultMessage(true); return messageSource; } }