Commit 5ff10c80 authored by Quxl's avatar Quxl

x

parent 3596836a
...@@ -5,6 +5,7 @@ import java.util.Locale; ...@@ -5,6 +5,7 @@ import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -45,19 +46,23 @@ public class I18NUtils { ...@@ -45,19 +46,23 @@ public class I18NUtils {
* @date 2018年4月11日 下午8:35:15 * @date 2018年4月11日 下午8:35:15
*/ */
public static String getMessage(String LangID,String key,Object...values){ public static String getMessage(String LangID,String key,Object...values){
if(StringUtil.isEmpty(LangID)){ //为空默认为中文 try {
Locale.setDefault(Locale.CHINA); if(StringUtil.isEmpty(LangID)){ //为空默认为中文
}else{
if(LangID.equals("900")){ //英文
Locale.setDefault(Locale.ENGLISH);
}else{
Locale.setDefault(Locale.CHINA); Locale.setDefault(Locale.CHINA);
}else{
if(LangID.equals("900")){ //英文
Locale.setDefault(Locale.ENGLISH);
}else{
Locale.setDefault(Locale.CHINA);
}
} }
} Locale locale = LocaleContextHolder.getLocale();
Locale locale = LocaleContextHolder.getLocale(); System.out.println("locale---------------"+locale);
System.out.println("locale---------------"+locale); String msg = source.getMessage(key, null, locale);
String msg = source.getMessage(key, null, locale); return MessageFormat.format(msg, values);
return MessageFormat.format(msg, values); } catch (Exception e) {
return key;
}
} }
......
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