Skip to content

Commit

Permalink
Merge branch 'next' into compat/203-212
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Nov 19, 2023
2 parents e04dc23 + c552d71 commit 1c3d943
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,7 +34,7 @@ class Settings : PersistentStateComponent<Settings> {
* 翻译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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*


/**
Expand All @@ -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<ListenerKey, MutableSet<ListenerInfo>>()
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -121,4 +122,9 @@ enum class TranslationEngine(
}
}

companion object {
val DEFAULT: TranslationEngine by lazy {
if (Locale.getDefault() == Locale.CHINA) MICROSOFT else GOOGLE
}
}
}

0 comments on commit 1c3d943

Please sign in to comment.