Browse Source

定义统一Locale获取国际化(I8Z7DA)

pull/485/MERGE
RuoYi 8 months ago
parent
commit
f6ce55be47
  1. 7
      ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
  2. 4
      ruoyi-common/src/main/java/com/ruoyi/common/utils/MessageUtils.java
  3. 4
      ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java

7
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@ -1,5 +1,7 @@
package com.ruoyi.common.constant;
import java.util.Locale;
/**
* 通用常量信息
*
@ -17,6 +19,11 @@ public class Constants
*/
public static final String GBK = "GBK";
/**
* 系统语言
*/
public static final Locale DEFAULT_LOCALE = Locale.SIMPLIFIED_CHINESE;
/**
* http请求
*/

4
ruoyi-common/src/main/java/com/ruoyi/common/utils/MessageUtils.java

@ -1,7 +1,7 @@
package com.ruoyi.common.utils;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.spring.SpringUtils;
/**
@ -21,6 +21,6 @@ public class MessageUtils
public static String message(String code, Object... args)
{
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
return messageSource.getMessage(code, args, Constants.DEFAULT_LOCALE);
}
}

4
ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java

@ -1,6 +1,5 @@
package com.ruoyi.framework.config;
import java.util.Locale;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
@ -8,6 +7,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import com.ruoyi.common.constant.Constants;
/**
* 资源文件配置加载
@ -22,7 +22,7 @@ public class I18nConfig implements WebMvcConfigurer
{
SessionLocaleResolver slr = new SessionLocaleResolver();
// 默认语言
slr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
slr.setDefaultLocale(Constants.DEFAULT_LOCALE);
return slr;
}

Loading…
Cancel
Save