From c552d71b5daf2a1724f6dd0dbb331c940cfe81de Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 20:30:37 +0800 Subject: [PATCH] Fix default translation engine --- src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt | 3 +-- .../yiiguxing/plugin/translate/trans/TranslateService.kt | 7 +------ .../plugin/translate/ui/settings/TranslationEngine.kt | 6 ++++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt index 4c134a861..01d8649e2 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt @@ -2,7 +2,6 @@ package cn.yiiguxing.plugin.translate import cn.yiiguxing.plugin.translate.trans.Lang import cn.yiiguxing.plugin.translate.ui.settings.TranslationEngine -import cn.yiiguxing.plugin.translate.ui.settings.TranslationEngine.GOOGLE import cn.yiiguxing.plugin.translate.util.* import cn.yiiguxing.plugin.translate.util.credential.SimpleStringCredentialManager import com.intellij.credentialStore.CredentialAttributes @@ -35,7 +34,7 @@ class Settings : PersistentStateComponent { * 翻译API */ var translator: TranslationEngine - by Delegates.observable(GOOGLE) { _, oldValue: TranslationEngine, newValue: TranslationEngine -> + by Delegates.observable(TranslationEngine.DEFAULT) { _, oldValue: TranslationEngine, newValue: TranslationEngine -> if (isInitialized && oldValue != newValue) { SETTINGS_CHANGE_PUBLISHER.onTranslatorChanged(this, newValue) } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt index 8968e307c..0f4bf15e0 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt @@ -21,7 +21,6 @@ import com.intellij.openapi.application.ModalityState import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.Logger import com.intellij.util.messages.MessageBusConnection -import java.util.* /** @@ -31,7 +30,7 @@ import java.util.* class TranslateService private constructor() : Disposable { @Volatile - var translator: Translator = DEFAULT_TRANSLATOR + var translator: Translator = GoogleTranslator private set private val listeners = mutableMapOf>() @@ -195,10 +194,6 @@ class TranslateService private constructor() : Disposable { private data class ListenerInfo(val modalityState: ModalityState, val listener: TranslateListener) companion object { - val DEFAULT_TRANSLATOR: Translator by lazy { - if (Locale.getDefault() == Locale.CHINA) MicrosoftTranslator else GoogleTranslator - } - val instance: TranslateService get() = ApplicationManager.getApplication().getService(TranslateService::class.java) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/settings/TranslationEngine.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/settings/TranslationEngine.kt index a5c47a03e..b312e1dc6 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/settings/TranslationEngine.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/settings/TranslationEngine.kt @@ -22,6 +22,7 @@ import cn.yiiguxing.plugin.translate.ui.AppKeySettingsDialog import cn.yiiguxing.plugin.translate.ui.AppKeySettingsPanel import cn.yiiguxing.plugin.translate.util.Settings import icons.TranslationIcons +import java.util.* import javax.swing.Icon enum class TranslationEngine( @@ -121,4 +122,9 @@ enum class TranslationEngine( } } + companion object { + val DEFAULT: TranslationEngine by lazy { + if (Locale.getDefault() == Locale.CHINA) MICROSOFT else GOOGLE + } + } }