package com.airlenet.web.i18n;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.MessageSourceAccessor;
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.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
public class I18nConfigBean extends WebMvcConfigurerAdapter {

	@Value("${i18n.messages?:default-message,message}")
	private String i18nMessages;

	@Value("${i18n.default_locale?:zh_CN}")
	private String defaultLocale;

	@Bean
	public ResourceBundleMessageSource messageSource() {
		ResourceBundleMessageSource bundleMessageSource = new ResourceBundleMessageSource();
		bundleMessageSource.setUseCodeAsDefaultMessage(true);
		bundleMessageSource.setBasenames(i18nMessages.split(","));
		return bundleMessageSource;
	}

	@Bean
	public MessageSourceAccessor messageSourceAccessor() {
		return new MessageSourceAccessor(messageSource());
	}

	@Bean
	public LocaleChangeInterceptor localeChangeInterceptor() {
		LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
		localeChangeInterceptor.setParamName("locale");
		return localeChangeInterceptor;
	}

	@Bean
	public LocaleResolver localeResolver() {
		CookieLocaleResolver localeResolver = new CookieLocaleResolver();
		localeResolver.setDefaultLocale(new Locale(defaultLocale));
		localeResolver.setCookieName("lang");
		return localeResolver;
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(localeChangeInterceptor());
	}

}

@@ -41,21 +41,135 @@
 ava.
-util.Locale;%0A
+nio.charset.Charset;%0Aimport java.util.Locale;%0A%0Aimport com.airlenet.core.PlayConstants;%0Aimport org.apache.commons.lang3.CharSet;
 %0Aimp
@@ -1061,16 +1061,123 @@
 ocale;%0A%0A
+%09@Value(%22$%7Bi18n.default_encoding?:%22+PlayConstants.characterEncoding+%22%7D%22)%0A%09private String defaultEncoding;%0A%0A
 %09@Bean%0A%09
@@ -1316,16 +1316,75 @@
 urce();%0A
+%09%09bundleMessageSource.setDefaultEncoding(defaultEncoding);%0A
 %09%09bundle

update i18n编码