diff --git a/backend/app/src/main/java/io/metersphere/config/BundleConfig.java b/backend/app/src/main/java/io/metersphere/config/BundleConfig.java new file mode 100644 index 0000000000..b8698d9384 --- /dev/null +++ b/backend/app/src/main/java/io/metersphere/config/BundleConfig.java @@ -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; + } +} diff --git a/backend/app/src/main/resources/commons.properties b/backend/app/src/main/resources/commons.properties index cbe933f38e..f24e32be9e 100644 --- a/backend/app/src/main/resources/commons.properties +++ b/backend/app/src/main/resources/commons.properties @@ -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 \ No newline at end of file +metersphere.file.batch-download-max=600MB +spring.messages.default-locale=zh_CN diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java index 6596dea0e0..2b38e1f092 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java @@ -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; } diff --git a/backend/services/api-test/src/test/resources/application.properties b/backend/services/api-test/src/test/resources/application.properties index b0a63a87c3..cf962fd88a 100644 --- a/backend/services/api-test/src/test/resources/application.properties +++ b/backend/services/api-test/src/test/resources/application.properties @@ -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 diff --git a/backend/services/bug-management/src/test/resources/application.properties b/backend/services/bug-management/src/test/resources/application.properties index cc8aec8783..d193f107b4 100644 --- a/backend/services/bug-management/src/test/resources/application.properties +++ b/backend/services/bug-management/src/test/resources/application.properties @@ -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 diff --git a/backend/services/case-management/src/test/resources/application.properties b/backend/services/case-management/src/test/resources/application.properties index 89bfe68a43..67ebb1ea77 100644 --- a/backend/services/case-management/src/test/resources/application.properties +++ b/backend/services/case-management/src/test/resources/application.properties @@ -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 diff --git a/backend/services/project-management/src/test/resources/application.properties b/backend/services/project-management/src/test/resources/application.properties index aa0f54dc4a..45771fff34 100644 --- a/backend/services/project-management/src/test/resources/application.properties +++ b/backend/services/project-management/src/test/resources/application.properties @@ -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 diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java index 78874444ec..8d20bbb3f9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserLocalConfigController.java @@ -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; + } + } diff --git a/backend/services/system-setting/src/test/resources/application.properties b/backend/services/system-setting/src/test/resources/application.properties index 5b019fd16c..45ed0b2d82 100644 --- a/backend/services/system-setting/src/test/resources/application.properties +++ b/backend/services/system-setting/src/test/resources/application.properties @@ -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 diff --git a/backend/services/test-plan/src/test/resources/application.properties b/backend/services/test-plan/src/test/resources/application.properties index eb53b7cddb..664e5fab2d 100644 --- a/backend/services/test-plan/src/test/resources/application.properties +++ b/backend/services/test-plan/src/test/resources/application.properties @@ -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