From 4121d011a9385645be42dee25c5267ad9e8136e2 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Fri, 17 Apr 2020 10:06:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20spring=20boot=20=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/config/I18nConfig.java | 7 +++++++ .../main/java/io/metersphere/i18n/Translator.java | 12 +++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/config/I18nConfig.java b/backend/src/main/java/io/metersphere/config/I18nConfig.java index 3d23aee8a9..8d5a5d5548 100644 --- a/backend/src/main/java/io/metersphere/config/I18nConfig.java +++ b/backend/src/main/java/io/metersphere/config/I18nConfig.java @@ -2,6 +2,7 @@ package io.metersphere.config; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.i18n.I18nManager; +import io.metersphere.i18n.Translator; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -20,6 +21,12 @@ public class I18nConfig { return new I18nManager(dirs); } + @Bean + @ConditionalOnMissingBean + public Translator translator() { + return new Translator(); + } + @Bean @ConditionalOnMissingBean public CommonBeanFactory commonBeanFactory() { diff --git a/backend/src/main/java/io/metersphere/i18n/Translator.java b/backend/src/main/java/io/metersphere/i18n/Translator.java index ace569512a..0f0303c466 100644 --- a/backend/src/main/java/io/metersphere/i18n/Translator.java +++ b/backend/src/main/java/io/metersphere/i18n/Translator.java @@ -2,23 +2,21 @@ package io.metersphere.i18n; import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.stereotype.Component; import javax.annotation.Resource; -@Component public class Translator { private static MessageSource messageSource; + @Resource + public void setMessageSource(MessageSource messageSource) { + Translator.messageSource = messageSource; + } + /** * 单Key翻译 */ public static String get(String key) { return messageSource.getMessage(key, null, "Not Support Key", LocaleContextHolder.getLocale()); } - - @Resource - public void setMessageSource(MessageSource messageSource) { - Translator.messageSource = messageSource; - } }