From e9c961b6ca042a65ce070d288f7425adedf253aa Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期四, 23 十一月 2023 17:18:54 +0800
Subject: [PATCH] 优化双语登出和字典
---
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties | 5 +-
ruoyi-admin/src/main/resources/i18n/messages.properties | 3 +
ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java | 18 ++++++++
ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties | 2 +
ruoyi-common/src/main/java/com/ruoyi/common/filter/MyI18nInterceptor.java | 33 ++++++++++------
5 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/ruoyi-admin/src/main/resources/i18n/messages.properties b/ruoyi-admin/src/main/resources/i18n/messages.properties
index 92311d1..c3bf526 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages.properties
@@ -81,7 +81,6 @@
menu.mqQueue=mq\u961F\u5217
menu.minio=minio\u5B58\u50A8
menu.minioEvent=\u5B58\u50A8\u4E8B\u4EF6
-menu.minioEventQuery=\u5B58\u50A8\u4E8B\u4EF6\u67E5\u8BE2
menu.sysApi=\u7CFB\u7EDF\u63A5\u53E3
menu.tiles3d=\u4E09\u7EF4\u5B9E\u666F
@@ -156,6 +155,7 @@
dic.data.sys.oper.type.force.out=\u5F3A\u9000
dic.data.sys.oper.type.gen=\u751F\u6210\u4EE3\u7801
dic.data.sys.oper.type.clear=\u6E05\u7A7A\u6570\u636E
+dic.data.sys.oper.type.control=\u63A7\u5236
dic.data.sys.common.status.success=\u6210\u529F
dic.data.sys.common.status.fail=\u6210\u529F
dic.data.camera.type.samll.camera=\u5C0F\u5149\u7535
@@ -183,6 +183,7 @@
dic.data.cameras.priority.user1=\u7528\u6237\u4E00\u7EA7
dic.data.cameras.priority.user2=\u7528\u6237\u4E8C\u7EA7
dic.data.cameras.priority.user3=\u7528\u6237\u4E09\u7EA7
+dic.data.cameras.priority.user4=\u7528\u6237\u56DB\u7EA7
dic.data.cameras.priority.sys.app.onekey=sys_app_onekey
dic.data.cameras.priority.sys.access.control=sys_access_control
dic.data.cameras.priority.sys.external=sys_external
diff --git a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
index c7a163f..9fb30c5 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
@@ -98,8 +98,8 @@
menu.accountUnlock=accountUnlock
menu.batchForceOut=batchForceOut
menu.singleForceOut=singleForceOut
-menu.codePreview=preview
-menu.codeGen=generator
+menu.preview=preview
+menu.generator=generator
menu.query=query
menu.add=add
menu.edit=edit
@@ -163,6 +163,7 @@
dic.data.sys.oper.type.force.out=forceLogout
dic.data.sys.oper.type.gen=genCode
dic.data.sys.oper.type.clear=clear
+dic.data.sys.oper.type.control=control
dic.data.sys.common.status.success=success
dic.data.sys.common.status.fail=fail
dic.data.camera.type.samll.camera=samll
diff --git a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
index 4338b05..be74d93 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages_zh_CN.properties
@@ -161,6 +161,7 @@
dic.data.sys.oper.type.force.out=\u5F3A\u9000
dic.data.sys.oper.type.gen=\u751F\u6210\u4EE3\u7801
dic.data.sys.oper.type.clear=\u6E05\u7A7A\u6570\u636E
+dic.data.sys.oper.type.control=\u63A7\u5236
dic.data.sys.common.status.success=\u6210\u529F
dic.data.sys.common.status.fail=\u6210\u529F
dic.data.camera.type.samll.camera=\u5C0F\u5149\u7535
@@ -188,6 +189,7 @@
dic.data.cameras.priority.user1=\u7528\u6237\u4E00\u7EA7
dic.data.cameras.priority.user2=\u7528\u6237\u4E8C\u7EA7
dic.data.cameras.priority.user3=\u7528\u6237\u4E09\u7EA7
+dic.data.cameras.priority.user4=\u7528\u6237\u56DB\u7EA7
dic.data.cameras.priority.sys.app.onekey=sys_app_onekey
dic.data.cameras.priority.sys.access.control=sys_access_control
dic.data.cameras.priority.sys.external=sys_external
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/MyI18nInterceptor.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/MyI18nInterceptor.java
index c8d828c..f134600 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/MyI18nInterceptor.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/MyI18nInterceptor.java
@@ -13,20 +13,27 @@
public class MyI18nInterceptor implements HandlerInterceptor {
@Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
- final String key = "language";
- //String language = "en_US";
- //String language = "zh_CN";
- String language = request.getHeader(key);
- if (language == null) {
- //String language = "en_US";
- language = "en_US";
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
+ try {
+ final String key = "language";
+ //String language = "en-US";
+ //String language = "zh-CN";
+ String language = request.getHeader(key);
+ if (language == null) {
+ //String language = "en-US";
+ language = "en-US";
+ }
+ // 鍓嶇浼犻�掔殑language蹇呴』鏄痾h-CN鏍煎紡鐨勶紝涓棿鐨刜蹇呴』瑕佸畬鏁达紝涓嶈兘鍙紶閫抸h鎴杄n
+ log.info("褰撳墠璇█={}", language);
+ Locale locale = new Locale(language.split("-")[0], language.split("-")[1]);
+ // 杩欐牱璧嬪�间互鍚庯紝MessageUtils.message鏂规硶灏变笉鐢ㄤ慨鏀逛簡
+ LocaleContextHolder.setLocale(locale);
}
- // 鍓嶇浼犻�掔殑language蹇呴』鏄痾h_CN鏍煎紡鐨勶紝涓棿鐨刜蹇呴』瑕佸畬鏁达紝涓嶈兘鍙紶閫抸h鎴杄n
- log.debug("褰撳墠璇█={}", language);
- Locale locale = new Locale(language.split("_")[0], language.split("_")[1]);
- // 杩欐牱璧嬪�间互鍚庯紝MessageUtils.message鏂规硶灏变笉鐢ㄤ慨鏀逛簡
- LocaleContextHolder.setLocale(locale);
+ catch (Exception ex)
+ {
+ log.error(ex.getMessage());
+ return false;
+ }
return true;
}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
index c01f691..14874ba 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
@@ -1,11 +1,16 @@
package com.ruoyi.framework.security.handle;
import java.io.IOException;
+import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.utils.MessageUtils;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import com.alibaba.fastjson2.JSON;
@@ -23,6 +28,7 @@
*
* @author ruoyi
*/
+@Slf4j
@Configuration
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler
{
@@ -45,7 +51,17 @@
// 鍒犻櫎鐢ㄦ埛缂撳瓨璁板綍
tokenService.delLoginUser(loginUser.getToken());
// 璁板綍鐢ㄦ埛閫�鍑烘棩蹇�
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "閫�鍑烘垚鍔�"));
+ //鍥介檯鍖�
+ final String key = "language";
+ String language = request.getHeader(key);
+ if (language == null) {
+ //String language = "en-US";
+ language = "en-US";
+ }
+ log.info("褰撳墠璇█={}", language);
+ Locale locale = new Locale(language.split("-")[0], language.split("-")[1]);
+ LocaleContextHolder.setLocale(locale);
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT,MessageUtils.message("user.logout.success")));
}
ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.success("閫�鍑烘垚鍔�")));
}
--
Gitblit v1.9.3