package com.nbclass.config;

import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import com.nbclass.szxgl.constant.ActivityConstants;
import com.nbclass.util.WebUtils;

/**
 * 语言国际化
 * @author Leon
 * @datetime 2019年4月1日 下午4:00:51
 */
public class MyLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
    //	String lang = request.getParameter("lang");
        String lang = StringUtils.trimToEmpty(WebUtils.getValueFromCookie(request, ActivityConstants.cookie_key_customer_lang)).toLowerCase();
    	if("en".equals(lang)){ //前端存值: zh/en
    		lang = "en_US";
    	}else{
    		lang = "zh_CN";
    	}
        
        Locale locale = Locale.getDefault();
        if(StringUtils.isNotBlank(lang)){
            String[] split = lang.split("_");
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
    	
    }
    
}