caojianbin
2 years ago
4 changed files with 95 additions and 7 deletions
@ -0,0 +1,76 @@ |
|||||||
|
package com.ruoyi.gateway.constant; |
||||||
|
|
||||||
|
import com.ruoyi.gateway.filter.AuthFilter; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.http.server.reactive.ServerHttpRequest; |
||||||
|
import org.springframework.web.server.ServerWebExchange; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Locale; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
public class MessagesConstant { |
||||||
|
private static final org.slf4j.Logger log = LoggerFactory.getLogger(MessagesConstant.class); |
||||||
|
/**令牌不能为空*/ |
||||||
|
public static final String MESSAGES_TOKE_EMPTY_EN="Token cannot be empty"; |
||||||
|
public static final String MESSAGES_TOKE_EMPTY_ZH="令牌不能为"; |
||||||
|
/**令牌已过期或验证不正确*/ |
||||||
|
public static final String MESSAGES_TOKE_EMPTY_OR_ERROR_EN="Token expired or incorrectly verified"; |
||||||
|
public static final String MESSAGES_TOKE_EMPTY_OR_ERROR_ZH="令牌已过期或验证不正确"; |
||||||
|
/**登录状态已过期*/ |
||||||
|
public static final String MESSAGES_LOGIN_STATUS_EXPIRED_EN="Login status has expired"; |
||||||
|
public static final String MESSAGES_LOGIN_STATUS_EXPIRED_ZH="登录状态已过期"; |
||||||
|
/**令牌验证失败*/ |
||||||
|
public static final String MESSAGES_TOKE_VERIFICATION_FAILED_EN="Token verification failed"; |
||||||
|
public static final String MESSAGES_TOKE_VERIFICATION_FAILED_ZH="令牌验证失败"; |
||||||
|
/**请求地址不允许访问*/ |
||||||
|
public static final String MESSAGES_REQUEST_ADDRESS_EN="The requested address does not allow access"; |
||||||
|
public static final String MESSAGES_REQUEST_ADDRESS_ZH="请求地址不允许访问"; |
||||||
|
/**服务未找到*/ |
||||||
|
public static final String MESSAGES_SERVICE_NOT_FOUND_EN="Service not found"; |
||||||
|
public static final String MESSAGES_SERVICE_NOT_FOUND_ZH="服务未找到"; |
||||||
|
/**内部服务器错误*/ |
||||||
|
public static final String MESSAGES_INTERNAL_SERVER_ERROR_EN="Internal server error"; |
||||||
|
public static final String MESSAGES_INTERNAL_SERVER_ERROR_ZH="内部服务器错误"; |
||||||
|
|
||||||
|
|
||||||
|
/**语言类型 中文*/ |
||||||
|
public static final String Language_ZH="zh"; |
||||||
|
/**语言类型 英文*/ |
||||||
|
public static final String Language_EN="en"; |
||||||
|
/**语言类型 key*/ |
||||||
|
public static final String HEADER_KEY="yisailanguage"; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 国际化处理 |
||||||
|
* @param exchange |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String getMessages(ServerWebExchange exchange, String zh_msg, String en_msg) { |
||||||
|
//给一个默认值
|
||||||
|
String msg=zh_msg; |
||||||
|
ServerHttpRequest request = exchange.getRequest(); |
||||||
|
if (request.getHeaders().containsKey(MessagesConstant.HEADER_KEY)) { |
||||||
|
String zh = exchange.getRequest().getHeaders().getFirst(MessagesConstant.Language_ZH); |
||||||
|
if (MessagesConstant.Language_ZH.equals(zh)) { |
||||||
|
msg = zh_msg; |
||||||
|
} else { |
||||||
|
msg = en_msg; |
||||||
|
} |
||||||
|
}else { |
||||||
|
String s = request.getHeaders().get("accept-language").get(0).split(",")[1]; |
||||||
|
log.info("获取头部的语言:{}",s); |
||||||
|
if (MessagesConstant.Language_ZH.equals(s)) { |
||||||
|
msg = zh_msg; |
||||||
|
} else { |
||||||
|
msg = en_msg; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
return msg; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue