package com.fzm.mall.server.front.config;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author lyz
 * @mail lyz@disanbo.com
 * @create 2021/1/25 13:55
 * @description
 */
public class MallLocaleResolver implements LocaleResolver {
    private final String DEFAULT_LOCALE_PARAM = "zh_CN";

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String clientLanguage = httpServletRequest.getHeader("Language");
        if (StringUtils.isEmpty(clientLanguage) || DEFAULT_LOCALE_PARAM.equals(clientLanguage)) {
            return Locale.CHINA;
        }
        return Locale.US;
    }

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

    }
}
