feat: 支持用户设置默认语言

This commit is contained in:
fit2-zhao 2024-08-09 16:22:08 +08:00 committed by Craftsman
parent 31c10984fb
commit b449f2fe79
10 changed files with 52 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -88,4 +88,5 @@ springdoc.swagger-ui.enabled=false
springdoc.api-docs.enabled=false
springdoc.api-docs.groups.enabled=true
#批量文件下载的最大值
metersphere.file.batch-download-max=600MB
metersphere.file.batch-download-max=600MB
spring.messages.default-locale=zh_CN

View File

@ -102,6 +102,8 @@ public class FilterChainUtils {
filterChainDefinitionMap.put("/test-plan/report/share/detail/**", "anon");
filterChainDefinitionMap.put("/test-plan/report/share/get/**", "anon");
filterChainDefinitionMap.put("/test-plan/report/share/get-layout/**", "anon");
// 默认语言
filterChainDefinitionMap.put("/user/local/config/default-locale", "anon");
return filterChainDefinitionMap;
}

View File

@ -67,6 +67,8 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false

View File

@ -63,6 +63,8 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false

View File

@ -60,6 +60,8 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false

View File

@ -63,6 +63,8 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false

View File

@ -12,6 +12,7 @@ import io.metersphere.system.utils.SessionUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -21,6 +22,8 @@ import java.util.List;
@RequestMapping("/user/local/config")
@Tag(name = "系统设置-个人中心-我的设置-本地执行")
public class UserLocalConfigController {
@Value("${spring.messages.default-locale}")
private String defaultLocale;
@Resource
private UserLocalConfigService userLocalConfigService;
@ -57,4 +60,10 @@ public class UserLocalConfigController {
public void update(@Validated @RequestBody UserLocalConfigUpdateRequest request) {
userLocalConfigService.update(request);
}
@GetMapping(value = "/default-locale")
public String defaultLocale() {
return defaultLocale;
}
}

View File

@ -64,6 +64,7 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false

View File

@ -61,6 +61,8 @@ spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB
# i18n
spring.messages.basename=i18n/commons,i18n/api,i18n/bug,i18n/case,i18n/plan,i18n/project,i18n/system
spring.messages.default-locale=zh_CN
# actuator
management.endpoints.web.exposure.include=*
management.endpoints.enabled-by-default=false