|
|
|
1
|
+package com.ruoyi.framework.config;
|
|
|
|
2
|
+
|
|
|
|
3
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
4
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
5
|
+import org.springframework.web.servlet.LocaleResolver;
|
|
|
|
6
|
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
|
7
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
8
|
+import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
|
|
|
9
|
+import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
|
|
|
10
|
+import com.ruoyi.common.constant.Constants;
|
|
|
|
11
|
+
|
|
|
|
12
|
+/**
|
|
|
|
13
|
+ * 资源文件配置加载
|
|
|
|
14
|
+ *
|
|
|
|
15
|
+ * @author ruoyi
|
|
|
|
16
|
+ */
|
|
|
|
17
|
+@Configuration
|
|
|
|
18
|
+public class I18nConfig implements WebMvcConfigurer
|
|
|
|
19
|
+{
|
|
|
|
20
|
+ @Bean
|
|
|
|
21
|
+ public LocaleResolver localeResolver()
|
|
|
|
22
|
+ {
|
|
|
|
23
|
+ SessionLocaleResolver slr = new SessionLocaleResolver();
|
|
|
|
24
|
+ // 默认语言
|
|
|
|
25
|
+ slr.setDefaultLocale(Constants.DEFAULT_LOCALE);
|
|
|
|
26
|
+ return slr;
|
|
|
|
27
|
+ }
|
|
|
|
28
|
+
|
|
|
|
29
|
+ @Bean
|
|
|
|
30
|
+ public LocaleChangeInterceptor localeChangeInterceptor()
|
|
|
|
31
|
+ {
|
|
|
|
32
|
+ LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
|
|
|
33
|
+ // 参数名
|
|
|
|
34
|
+ lci.setParamName("lang");
|
|
|
|
35
|
+ return lci;
|
|
|
|
36
|
+ }
|
|
|
|
37
|
+
|
|
|
|
38
|
+ @Override
|
|
|
|
39
|
+ public void addInterceptors(InterceptorRegistry registry)
|
|
|
|
40
|
+ {
|
|
|
|
41
|
+ registry.addInterceptor(localeChangeInterceptor());
|
|
|
|
42
|
+ }
|
|
|
|
43
|
+} |