提交 3bd37a15 编写于 作者: O o2sword

多语言国际化5

上级 124e84c8
......@@ -2,6 +2,6 @@ com.x.base.core.project.exception.ExceptionAccessDenied=User :{} Insufficient pe
com.x.base.core.project.exception.ExceptionAccessDenied_1=User :{} access object class:{}, id:{}, insufficient permission.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist=User :{} Insufficient permissions or the object does not exist.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist_1=User :{} Insufficient permission or object does not exist, {}.
com.x.base.core.project.exception.ExceptionEntityNotExist=The {2} object identified as :{1} does not exist.
com.x.base.core.project.exception.ExceptionEntityNotExist=The {1} object identified as :{0} does not exist.
com.x.base.core.project.exception.ExceptionEntityNotExist_1=The object identified as :{} does not exist.
com.x.base.core.project.exception.ExceptionEntityNotExist_2=Object of type: {} does not exist.
......@@ -59,4 +59,5 @@ public abstract class LanguagePromptException extends PromptException {
public void setLanguageKey(String languageKey) {
this.languageKey = languageKey;
}
}
......@@ -78,7 +78,10 @@ public class ResponseFactory {
if (result.getType().equals(ActionResult.Type.error)) {
if ((result.throwable instanceof LanguagePromptException)) {
LanguagePromptException e = (LanguagePromptException)result.throwable;
result.setMessage((e.getFormatMessage(result.getPrompt(), request.getHeader(Accept_Language))));
String message = e.getFormatMessage(result.getPrompt(), request.getHeader(Accept_Language));
if(StringUtils.isNotBlank(message)) {
result.setMessage(message);
}
}
if ((result.throwable instanceof CallbackPromptException)) {
return Response.ok(callbackError(result)).build();
......
package com.x.base.core.project.tools;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import java.util.Locale;
......@@ -8,6 +10,8 @@ import java.util.ResourceBundle;
public class LanguageTools {
private static Logger logger = LoggerFactory.getLogger(LanguageTools.class);
private final static String LANGUAGE_PLATFORM = "language.platform";
public static String getValue(String key) {
......@@ -15,54 +19,66 @@ public class LanguageTools {
}
public static String getValue(String key, String locale) {
String message = null;
if(StringUtils.isBlank(key)){
return null;
}
ResourceBundle resourceBundle = null;
if(StringUtils.isBlank(locale)){
try {
locale = Config.person().getLanguage();
} catch (Exception e) {
try {
ResourceBundle resourceBundle = null;
if(StringUtils.isBlank(locale)){
try {
locale = Config.person().getLanguage();
} catch (Exception e) {
}
}
}
if(StringUtils.isBlank(locale)){
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.getDefault());
}else if("zh".equalsIgnoreCase(locale) || "zh_CN".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.SIMPLIFIED_CHINESE);
}else if(locale.toLowerCase().startsWith("en")) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.ENGLISH);
}else if("zh_HK".equalsIgnoreCase(locale) || "zh_TW".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.TRADITIONAL_CHINESE);
}else{
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.getDefault());
if(StringUtils.isBlank(locale)){
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.getDefault());
}else if("zh".equalsIgnoreCase(locale) || "zh_CN".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.SIMPLIFIED_CHINESE);
}else if(locale.toLowerCase().startsWith("en")) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.ENGLISH);
}else if("zh_HK".equalsIgnoreCase(locale) || "zh_TW".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.TRADITIONAL_CHINESE);
}else{
resourceBundle = ResourceBundle.getBundle(LANGUAGE_PLATFORM, Locale.getDefault());
}
message = resourceBundle.getString(key);
} catch (Exception e) {
logger.print("LanguageTools resourceBundle error:"+e.getMessage());
}
return resourceBundle.getString(key);
return message;
}
public static String getValue(String baseName ,String key, String locale) {
String message = null;
if(StringUtils.isBlank(key)){
return null;
}
ResourceBundle resourceBundle = null;
if(StringUtils.isBlank(locale)){
try {
locale = Config.person().getLanguage();
} catch (Exception e) {
try {
ResourceBundle resourceBundle = null;
if(StringUtils.isBlank(locale)){
try {
locale = Config.person().getLanguage();
} catch (Exception e) {
}
}
}
if(StringUtils.isBlank(locale)){
resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault());
}else if("zh".equalsIgnoreCase(locale) || "zh_CN".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.SIMPLIFIED_CHINESE);
}else if(locale.toLowerCase().startsWith("en")) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.ENGLISH);
}else if("zh_HK".equalsIgnoreCase(locale) || "zh_TW".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.TRADITIONAL_CHINESE);
}else{
resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault());
if(StringUtils.isBlank(locale)){
resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault());
}else if("zh".equalsIgnoreCase(locale) || "zh_CN".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.SIMPLIFIED_CHINESE);
}else if(locale.toLowerCase().startsWith("en")) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.ENGLISH);
}else if("zh_HK".equalsIgnoreCase(locale) || "zh_TW".equalsIgnoreCase(locale)) {
resourceBundle = ResourceBundle.getBundle(baseName, Locale.TRADITIONAL_CHINESE);
}else{
resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault());
}
message = resourceBundle.getString(key);
} catch (Exception e) {
logger.print("LanguageTools resourceBundle error:"+e.getMessage());
}
return resourceBundle.getString(key);
return message;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册