feat: 支持用户设置默认语言
This commit is contained in:
parent
31c10984fb
commit
b449f2fe79
|
@ -0,0 +1,28 @@
|
||||||
|
package io.metersphere.config;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class BundleConfig {
|
||||||
|
@Value("${spring.messages.default-locale}")
|
||||||
|
private String defaultLocale;
|
||||||
|
@Value("${spring.messages.basename}")
|
||||||
|
private String[] basements;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ResourceBundleMessageSource messageSource() {
|
||||||
|
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
||||||
|
Locale defaultLocale = Locale.forLanguageTag(this.defaultLocale);
|
||||||
|
// 设置消息资源文件的基名
|
||||||
|
messageSource.setBasenames(basements);
|
||||||
|
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name()); // 设置编码
|
||||||
|
messageSource.setDefaultLocale(defaultLocale); // 设置默认语言
|
||||||
|
return messageSource;
|
||||||
|
}
|
||||||
|
}
|
|
@ -89,3 +89,4 @@ springdoc.api-docs.enabled=false
|
||||||
springdoc.api-docs.groups.enabled=true
|
springdoc.api-docs.groups.enabled=true
|
||||||
#批量文件下载的最大值
|
#批量文件下载的最大值
|
||||||
metersphere.file.batch-download-max=600MB
|
metersphere.file.batch-download-max=600MB
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
|
@ -102,6 +102,8 @@ public class FilterChainUtils {
|
||||||
filterChainDefinitionMap.put("/test-plan/report/share/detail/**", "anon");
|
filterChainDefinitionMap.put("/test-plan/report/share/detail/**", "anon");
|
||||||
filterChainDefinitionMap.put("/test-plan/report/share/get/**", "anon");
|
filterChainDefinitionMap.put("/test-plan/report/share/get/**", "anon");
|
||||||
filterChainDefinitionMap.put("/test-plan/report/share/get-layout/**", "anon");
|
filterChainDefinitionMap.put("/test-plan/report/share/get-layout/**", "anon");
|
||||||
|
// 默认语言
|
||||||
|
filterChainDefinitionMap.put("/user/local/config/default-locale", "anon");
|
||||||
|
|
||||||
return filterChainDefinitionMap;
|
return filterChainDefinitionMap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
|
@ -63,6 +63,8 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
|
@ -60,6 +60,8 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
|
@ -63,6 +63,8 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
|
@ -12,6 +12,7 @@ import io.metersphere.system.utils.SessionUtils;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ import java.util.List;
|
||||||
@RequestMapping("/user/local/config")
|
@RequestMapping("/user/local/config")
|
||||||
@Tag(name = "系统设置-个人中心-我的设置-本地执行")
|
@Tag(name = "系统设置-个人中心-我的设置-本地执行")
|
||||||
public class UserLocalConfigController {
|
public class UserLocalConfigController {
|
||||||
|
@Value("${spring.messages.default-locale}")
|
||||||
|
private String defaultLocale;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserLocalConfigService userLocalConfigService;
|
private UserLocalConfigService userLocalConfigService;
|
||||||
|
@ -57,4 +60,10 @@ public class UserLocalConfigController {
|
||||||
public void update(@Validated @RequestBody UserLocalConfigUpdateRequest request) {
|
public void update(@Validated @RequestBody UserLocalConfigUpdateRequest request) {
|
||||||
userLocalConfigService.update(request);
|
userLocalConfigService.update(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/default-locale")
|
||||||
|
public String defaultLocale() {
|
||||||
|
return defaultLocale;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
|
@ -61,6 +61,8 @@ spring.servlet.multipart.max-file-size=500MB
|
||||||
spring.servlet.multipart.max-request-size=500MB
|
spring.servlet.multipart.max-request-size=500MB
|
||||||
# i18n
|
# i18n
|
||||||
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
|
||||||
|
spring.messages.default-locale=zh_CN
|
||||||
|
|
||||||
# actuator
|
# actuator
|
||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
management.endpoints.enabled-by-default=false
|
management.endpoints.enabled-by-default=false
|
||||||
|
|
Loading…
Reference in New Issue