From e46a2c2ea8f9c5d146bb7b17e27b01255ffe0f91 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 16 Aug 2024 11:15:42 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=BB=98=E8=AE=A4=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E4=BC=98=E5=85=88=E7=BA=A7=E9=80=89=E6=8B=A9=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fit2-zhao --- .../controller/SystemParameterController.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/SystemParameterController.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/SystemParameterController.java index 7ff2a4f83d..81bce2125e 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/SystemParameterController.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/SystemParameterController.java @@ -7,23 +7,27 @@ import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogModule; import io.metersphere.commons.constants.ParamConstants; import io.metersphere.commons.constants.PermissionConstants; -import io.metersphere.request.HeaderRequest; +import io.metersphere.commons.user.SessionUser; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.ldap.domain.LdapInfo; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.notice.domain.MailInfo; +import io.metersphere.request.HeaderRequest; import io.metersphere.service.BaseUserService; import io.metersphere.service.SystemParameterService; +import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.env.Environment; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; import java.time.Duration; import java.util.HashMap; import java.util.List; +import java.util.Optional; @RestController @RequestMapping(value = "/system") @@ -145,8 +149,13 @@ public class SystemParameterController { @GetMapping(value = "/default-locale") public String defaultLocale() { - return defaultLocale; + SessionUser user = SessionUtils.getUser(); + String language = Optional.ofNullable(user) + .map(SessionUser::getLanguage) + .filter(StringUtils::isNotBlank) + .orElse(defaultLocale); + + return language.replace("_", "-"); } - }