From c06a02fb970f6244cb481ee45ad13b46e260fad1 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 06 八月 2021 18:59:08 +0800
Subject: [PATCH] add 增加 完整国际化解决方案
---
ruoyi-admin/src/main/resources/i18n/messages_en_US.properties | 2 +-
ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
README.md | 1 +
3 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/README.md b/README.md
index 1a71ece..b0d7ef2 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,7 @@
* 宸ュ叿绫绘鏋� Hutool銆丩ombok 鍑忓皯浠g爜鍐椾綑 澧炲姞瀹夊叏鎬�
* 浠g爜鐢熸垚鍣� 涓�閿敓鎴愬墠鍚庣浠g爜
* 閮ㄧ讲鏂瑰紡 Docker 瀹瑰櫒缂栨帓 涓�閿儴缃蹭笟鍔¢泦缇�
+* 鍥介檯鍖� Spring 鏍囧噯鍥介檯鍖栨柟瑙e喅鏂规
## 鍙傝�冩枃妗�
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 4187065..8a3fba3 100644
--- a/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
+++ b/ruoyi-admin/src/main/resources/i18n/messages_en_US.properties
@@ -16,8 +16,8 @@
user.email.not.valid=
user.mobile.phone.number.not.valid=
user.login.success=
+user.register.success=register success
user.notfound=
-user.forcelogout=
user.unknown.error=
##鏂囦欢涓婁紶娑堟伅
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java
new file mode 100644
index 0000000..48b341b
--- /dev/null
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java
@@ -0,0 +1,48 @@
+package com.ruoyi.framework.config;
+
+import cn.hutool.core.util.StrUtil;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.LocaleResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Locale;
+
+/**
+ * 鍥介檯鍖栭厤缃�
+ *
+ * @author Lion Li
+ */
+@Configuration
+public class I18nConfig {
+
+ @Bean
+ public LocaleResolver localeResolver() {
+ return new I18nLocaleResolver();
+ }
+
+ /**
+ * 鑾峰彇璇锋眰澶村浗闄呭寲淇℃伅
+ */
+ static class I18nLocaleResolver implements LocaleResolver {
+
+ @NotNull
+ @Override
+ public Locale resolveLocale(HttpServletRequest httpServletRequest) {
+ String language = httpServletRequest.getHeader("content-language");
+ Locale locale = Locale.getDefault();
+ if (StrUtil.isNotBlank(language)) {
+ String[] split = language.split("_");
+ locale = new Locale(split[0], split[1]);
+ }
+ return locale;
+ }
+
+ @Override
+ public void setLocale(@NotNull HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
+
+ }
+ }
+}
--
Gitblit v1.9.3