| package com.xcong.excoin.configurations.i18n; | 
|   | 
| import cn.hutool.core.util.StrUtil; | 
| import org.springframework.context.annotation.Configuration; | 
| import org.springframework.web.servlet.LocaleResolver; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.util.Locale; | 
|   | 
| /** | 
|  * @author wzy | 
|  * @date 2020-04-30 14:56 | 
|  **/ | 
| @Configuration | 
| public class CustomLocaleResolver implements LocaleResolver { | 
|   | 
|     @Override | 
|     public Locale resolveLocale(HttpServletRequest httpServletRequest) { | 
|         String lang = httpServletRequest.getHeader("lang"); | 
|         if(StrUtil.isBlank(lang)) { | 
|             return new Locale("zh", "CN"); | 
|         } else { | 
|             String[] splite = lang.split("_"); | 
|             return new Locale(splite[0], splite[1]); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) { | 
|   | 
|     } | 
| } |