From bc1455314c8c1a24701da64d8f7eb7ee5781cf86 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 23 Sep 2024 18:29:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=A2=9E=E5=8A=A0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E8=AF=AD=E8=A8=80=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=88=96=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E6=97=B6=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/sdk/util/Translator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/Translator.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/Translator.java index ffbf2e583c..7a82de58c0 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/Translator.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/Translator.java @@ -4,6 +4,8 @@ import jakarta.annotation.Resource; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; +import java.util.Locale; + public class Translator { private static MessageSource messageSource; @@ -26,10 +28,19 @@ public class Translator { return messageSource.getMessage(key, null, defaultMessage, LocaleContextHolder.getLocale()); } + /** + * 单Key翻译,并指定默认语言 + */ + public static String get(String key, Locale locale) { + return messageSource.getMessage(key, null, locale); + } + /** * 带参数 */ public static String getWithArgs(String key, Object... args) { return messageSource.getMessage(key, args, "Not Support Key: " + key, LocaleContextHolder.getLocale()); } + + }