add:国际化配置
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package org.nl.common.language;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.common.utils.MapOf;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class InitLocaleResolver implements LocaleResolver {
|
||||
public static Map<String,String> Language_Country = MapOf.of("id","in-ID","in","in-ID","en-US,en;q=0.9","en-US","en","en-US","zh","zh-CN","ko","ko-KR");
|
||||
public static String language = "";
|
||||
@Override
|
||||
public Locale resolveLocale(HttpServletRequest request) {
|
||||
String header = request.getHeader("Accept-Language");
|
||||
if (StringUtils.isNotEmpty(header)){
|
||||
String lang = Language_Country.get(header);
|
||||
language = lang;
|
||||
if (StringUtils.isNotEmpty(lang)){
|
||||
String[] l = lang.split("-");
|
||||
//印尼的ISO标准国家代码为id-ID
|
||||
return new Locale(l[0], l[1]);
|
||||
}
|
||||
}
|
||||
return Locale.getDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
|
||||
}
|
||||
public String getLanguage(){
|
||||
return language;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.nl.common.language;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
|
||||
public class LangProcess {
|
||||
|
||||
public static String msg(String code,String...args){
|
||||
MessageSource bean = SpringContextHolder.getBean(MessageSource.class);
|
||||
if (StringUtils.isEmpty(code)){
|
||||
return " ";
|
||||
}
|
||||
String message = bean.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.nl.common.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import org.nl.common.language.LangProcess;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AssertNullUtils {
|
||||
|
||||
public static void batch(Map<String,Object> paramCheck){
|
||||
if (CollectionUtils.isEmpty(paramCheck)){
|
||||
throw new BadRequestException(LangProcess.msg("common_checkNull"));
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : paramCheck.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if (ObjectUtil.isEmpty(value)){
|
||||
throw new BadRequestException(LangProcess.msg("common_checkNull",entry.getKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user