From bc34fe73f7bb44f3f745677df9e0284dbb4af7fb Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 16 Aug 2024 10:52:47 +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 --- .../system/controller/UserLocalConfigController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 d15c80f596..e28e8bb9b0 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 @@ -4,6 +4,7 @@ package io.metersphere.system.controller; import io.metersphere.system.domain.UserLocalConfig; import io.metersphere.system.dto.UserLocalConfigAddRequest; import io.metersphere.system.dto.UserLocalConfigUpdateRequest; +import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.service.UserLocalConfigLogService; @@ -12,11 +13,13 @@ 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.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.Optional; @RestController @RequestMapping("/user/local/config") @@ -63,7 +66,12 @@ public class UserLocalConfigController { @GetMapping(value = "/default-locale") public String defaultLocale() { - return defaultLocale.replace("_", "-"); - } + SessionUser user = SessionUtils.getUser(); + String language = Optional.ofNullable(user) + .map(SessionUser::getLanguage) + .filter(StringUtils::isNotBlank) + .orElse(defaultLocale); + return language.replace("_", "-"); + } }