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()); } + + }