Browse Source

网关国际化改造02

master
caojianbin 2 years ago
parent
commit
de4de57a68
  1. 5
      ruoyi-gateway/src/main/java/com/ruoyi/gateway/constant/MessagesConstant.java

5
ruoyi-gateway/src/main/java/com/ruoyi/gateway/constant/MessagesConstant.java

@ -49,7 +49,7 @@ public class MessagesConstant {
*/ */
public static String getMessages(ServerWebExchange exchange, String zh_msg, String en_msg) { public static String getMessages(ServerWebExchange exchange, String zh_msg, String en_msg) {
//给一个默认值 //给一个默认值
String msg=zh_msg; String msg=en_msg;
ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest request = exchange.getRequest();
if (request.getHeaders().containsKey(MessagesConstant.HEADER_KEY)) { if (request.getHeaders().containsKey(MessagesConstant.HEADER_KEY)) {
String zh = exchange.getRequest().getHeaders().getFirst(MessagesConstant.Language_ZH); String zh = exchange.getRequest().getHeaders().getFirst(MessagesConstant.Language_ZH);
@ -59,7 +59,8 @@ public class MessagesConstant {
msg = en_msg; msg = en_msg;
} }
}else { }else {
String s = request.getHeaders().get("accept-language").get(0).split(",")[1]; String s = request.getHeaders().get("accept-language").get(0).split(",")[0].split("-")[0];
log.info("获取头部的accept-language值:",request.getHeaders().get("accept-language"));
log.info("获取头部的语言:{}",s); log.info("获取头部的语言:{}",s);
if (MessagesConstant.Language_ZH.equals(s)) { if (MessagesConstant.Language_ZH.equals(s)) {
msg = zh_msg; msg = zh_msg;

Loading…
Cancel
Save