Commit 8b819a24 authored by Quxl's avatar Quxl

xx

parent 92bc2456
...@@ -20,18 +20,22 @@ public class LocaleCookieInterceptor extends HandlerInterceptorAdapter { ...@@ -20,18 +20,22 @@ public class LocaleCookieInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception { public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
Cookie[] cookies = req.getCookies(); Cookie[] cookies = req.getCookies();
for(Cookie cookie : cookies) { if(cookies != null && cookies.length > 0) {
if(cookie.getName().equals(language)) { for(Cookie cookie : cookies) {
String str = cookie.getValue(); if(cookie.getName().equals(language)) {
if(StringUtil.isBlank(str)) { String str = cookie.getValue();
str = "zh_CN"; if(StringUtil.isBlank(str)) {
str = "zh_CN";
}
String[] kv = str.split("_");
String language = kv[0];
String country = kv.length == 2 ? kv[1] : null;
LocaleContextHolder.setLocale(new Locale(language, country));
return super.preHandle(req, resp, handler);
} }
String[] kv = str.split("_");
String language = kv[0];
String country = kv.length == 2 ? kv[1] : null;
LocaleContextHolder.setLocale(new Locale(language, country));
} }
} }
LocaleContextHolder.setLocale(Locale.CHINA);
return super.preHandle(req, resp, handler); return super.preHandle(req, resp, handler);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment