diff --git a/README.md b/README.md index 1a71ecee..b0d7ef24 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ RuoYi-Vue-Plus 是基于 RuoYi-Vue 针对 `分布式集群` 场景升级 定期 * 工具类框架 Hutool、Lombok 减少代码冗余 增加安全性 * 代码生成器 一键生成前后端代码 * 部署方式 Docker 容器编排 一键部署业务集群 +* 国际化 Spring 标准国际化方解决方案 ## 参考文档 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 41870654..8a3fba3f 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.password.not.valid= 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 00000000..48b341be --- /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) { + + } + } +}