From a5b3ec2b92b074ed7c265c24bc3b25630622de73 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Fri, 30 Aug 2024 16:25:35 +0800 Subject: [PATCH 1/7] Fix file overlap locking fix: #6044 --- .../plugin/translate/wordbook/WordBookService.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/wordbook/WordBookService.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/wordbook/WordBookService.kt index 5320d243e..d46c2654a 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/wordbook/WordBookService.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/wordbook/WordBookService.kt @@ -636,11 +636,13 @@ class WordBookService : Disposable { private inline fun lock(block: () -> T): T { return RandomAccessFile(LOCK_FILE.toFile(), "rw").use { lockFile -> - val lock = lockFile.channel.lock() - try { - block() - } finally { - lock.release() + synchronized(LOCK_FILE) { + val lock = lockFile.channel.lock() + try { + block() + } finally { + lock.release() + } } } } From 9c0b446d2b51d934bfed63d8a2343c600e83a738 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Fri, 30 Aug 2024 17:17:22 +0800 Subject: [PATCH 2/7] Delay show `Got It` tooltip --- .../plugin/translate/ui/TranslationWidget.kt | 18 +++++++++++++----- .../plugin/translate/update/UpdateListener.kt | 2 +- .../plugin/translate/update/UpdateManager.kt | 10 +++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt index 6723f45c3..441cbbe0c 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt @@ -25,9 +25,11 @@ import com.intellij.openapi.wm.impl.status.TextPanel.WithIconAndArrows import com.intellij.ui.ClickListener import com.intellij.ui.GotItTooltip import com.intellij.ui.awt.RelativePoint +import com.intellij.util.concurrency.AppExecutorUtil import org.jetbrains.concurrency.runAsync import java.awt.Point import java.awt.event.MouseEvent +import java.util.concurrent.TimeUnit import javax.swing.JComponent /** @@ -102,13 +104,19 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico project.messageBus .connect(disposable) .subscribe(UpdateListener.TOPIC, object : UpdateListener { - override fun onPostUpdate() { + override fun onPostUpdate(hasUpdate: Boolean) { Disposer.dispose(disposable) - if (project.isDisposed) { - return + val runnable = { + if (!project.isDisposed) { + DumbService.getInstance(project).smartInvokeLater { + showGotItTooltipIfNeed() + } + } } - DumbService.getInstance(project).smartInvokeLater { - showGotItTooltipIfNeed() + if (hasUpdate) { + AppExecutorUtil.getAppScheduledExecutorService().schedule(runnable, 1, TimeUnit.SECONDS) + } else { + runnable() } } }) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateListener.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateListener.kt index 512453099..3cda48cb5 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateListener.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateListener.kt @@ -8,7 +8,7 @@ interface UpdateListener { * Called after the update check is completed. If the update notification is shown, * this method will be called after the notification is closed. */ - fun onPostUpdate() {} + fun onPostUpdate(hasUpdate: Boolean) {} companion object { @Topic.AppLevel diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt index ac97ef009..65239982f 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt @@ -66,14 +66,14 @@ class UpdateManager : BaseStartupActivity(true) { val properties: PropertiesComponent = PropertiesComponent.getInstance() val lastVersionString = properties.getValue(VERSION_PROPERTY, Version.INITIAL_VERSION) if (versionString == lastVersionString) { - onPostUpdate() + onPostUpdate(false) return } val version = Version(versionString) val lastVersion = Version.getOrElse(lastVersionString) { Version() } if (version.isSameVersion(lastVersion)) { - onPostUpdate() + onPostUpdate(false) return } @@ -139,7 +139,7 @@ class UpdateManager : BaseStartupActivity(true) { WhatsNew.browse(project, version) } } - onPostUpdate() + onPostUpdate(true) } invokeLaterIfNeeded(expired = project.disposed) { @@ -201,9 +201,9 @@ class UpdateManager : BaseStartupActivity(true) { return true } - private fun onPostUpdate() { + private fun onPostUpdate(hasUpdate: Boolean) { invokeLaterIfNeeded { - Application.messageBus.syncPublisher(UpdateListener.TOPIC).onPostUpdate() + Application.messageBus.syncPublisher(UpdateListener.TOPIC).onPostUpdate(hasUpdate) } } From 9399f12b687c498f5e92ba7d40acb47e70d9fa40 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Mon, 2 Sep 2024 16:47:50 +0800 Subject: [PATCH 3/7] Add new language: Chinese (`zh`) --- .../cn/yiiguxing/plugin/translate/trans/Languages.kt | 7 +++++-- .../plugin/translate/trans/ali/AliLanguageAdapter.kt | 6 +++--- .../plugin/translate/trans/baidu/BaiduLanguageAdapter.kt | 6 +++--- .../translate/trans/google/GoogleLanguageAdapter.kt | 1 + .../translate/trans/microsoft/MicrosoftLanguageAdapter.kt | 3 ++- .../plugin/translate/trans/openai/OpenAiLanguages.kt | 2 +- .../translate/trans/youdao/YoudaoLanguageAdapter.kt | 4 ++-- .../cn/yiiguxing/plugin/translate/tts/GoogleTTSPlayer.kt | 2 +- .../plugin/translate/tts/microsoft/EdgeTTSVoiceManager.kt | 2 +- src/main/resources/messages/LanguageBundle.properties | 3 ++- src/main/resources/messages/LanguageBundle_ja.properties | 3 ++- src/main/resources/messages/LanguageBundle_ko.properties | 3 ++- .../resources/messages/LanguageBundle_zh_CN.properties | 3 ++- .../cn/yiiguxing/plugin/translate/ui/TranslationUiTest.kt | 8 ++++---- 14 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/Languages.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/Languages.kt index 371f54c88..c81668034 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/Languages.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/Languages.kt @@ -85,7 +85,7 @@ enum class Lang( CHICHEWA("chichewa", "ny"), /** 中文 */ - CHINESE("chinese", "zh-CN"), + CHINESE("chinese", "zh"), /** 粤语 */ CHINESE_CANTONESE("chinese.cantonese", "zh-CANTONESE"), @@ -93,6 +93,9 @@ enum class Lang( /** 文言文 */ CHINESE_CLASSICAL("chinese.classical", "zh-CLASSICAL"), + /** 中文(简体) */ + CHINESE_SIMPLIFIED("chinese.simplified", "zh-CN"), + /** 中文(繁体) */ CHINESE_TRADITIONAL("chinese.traditional", "zh-TW"), @@ -459,7 +462,7 @@ enum class Lang( return when (localeLanguage) { Locale.CHINESE.language -> when (Locale.getDefault().country) { "HK", "TW" -> CHINESE_TRADITIONAL - else -> CHINESE + else -> CHINESE_SIMPLIFIED } else -> values().find { Locale(it.code).language.equals(localeLanguage, ignoreCase = true) } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt index 530c30664..838978688 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt @@ -10,7 +10,7 @@ object AliLanguageAdapter : BaseLanguageAdapter() { override val supportedSourceLanguages: List = listOf( Lang.AUTO, - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, Lang.CHINESE_TRADITIONAL, Lang.ENGLISH, Lang.JAPANESE, @@ -31,7 +31,7 @@ object AliLanguageAdapter : BaseLanguageAdapter() { ) override val supportedTargetLanguages: List = listOf( - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH, Lang.JAPANESE, Lang.KOREAN, @@ -49,7 +49,7 @@ object AliLanguageAdapter : BaseLanguageAdapter() { ) override fun getAdaptedLanguages(): Map = mapOf( - "zh" to Lang.CHINESE, + "zh" to Lang.CHINESE_SIMPLIFIED, "zh-tw" to Lang.CHINESE_TRADITIONAL, "yue" to Lang.CHINESE_CANTONESE, "fil" to Lang.FILIPINO, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt index 92fd00c13..ecc5a2d54 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt @@ -10,7 +10,7 @@ object BaiduLanguageAdapter : BaseLanguageAdapter() { /** 通用版支持的语言列表 */ private val SUPPORTED_LANGUAGES: List = listOf( - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH, Lang.CHINESE_TRADITIONAL, Lang.CHINESE_CANTONESE, @@ -43,7 +43,7 @@ object BaiduLanguageAdapter : BaseLanguageAdapter() { /** 尊享版支持的语言列表 */ @Suppress("unused") private val SUPPORTED_LANGUAGES_PRO: List = listOf( - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH, Lang.CHINESE_TRADITIONAL, Lang.CHINESE_CANTONESE, @@ -141,7 +141,7 @@ object BaiduLanguageAdapter : BaseLanguageAdapter() { "ben" to Lang.BENGALI, "bos" to Lang.BOSNIAN, "bul" to Lang.BULGARIAN, - "zh" to Lang.CHINESE, + "zh" to Lang.CHINESE_SIMPLIFIED, "cht" to Lang.CHINESE_TRADITIONAL, "wyw" to Lang.CHINESE_CLASSICAL, "yue" to Lang.CHINESE_CANTONESE, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt index d19207320..b7e4d0369 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt @@ -11,6 +11,7 @@ object GoogleLanguageAdapter : BaseLanguageAdapter() { private val UNSUPPORTED_LANGUAGES: Set = setOf( Lang.ASSAMESE, Lang.BASHKIR, + Lang.CHINESE, // 己俱体分为 `中文(简体)` Lang.CHINESE_CANTONESE, Lang.CHINESE_CLASSICAL, Lang.DARI, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt index 9b9942fa8..650ffdc09 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt @@ -12,6 +12,7 @@ internal object MicrosoftLanguageAdapter : BaseLanguageAdapter() { Lang.BELARUSIAN, Lang.CEBUANO, Lang.CHICHEWA, + Lang.CHINESE, // 己俱体分为 `中文(简体)` 和 `中文(繁体)` 等 Lang.CORSICAN, Lang.ENGLISH_AMERICAN, Lang.ENGLISH_BRITISH, @@ -44,7 +45,7 @@ internal object MicrosoftLanguageAdapter : BaseLanguageAdapter() { override fun getAdaptedLanguages(): Map = mapOf( "yue" to Lang.CHINESE_CANTONESE, "lzh" to Lang.CHINESE_CLASSICAL, - "zh-Hans" to Lang.CHINESE, + "zh-Hans" to Lang.CHINESE_SIMPLIFIED, "zh-Hant" to Lang.CHINESE_TRADITIONAL, "fil" to Lang.FILIPINO, "he" to Lang.HEBREW, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiLanguages.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiLanguages.kt index a4c3d2f2a..c7529825e 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiLanguages.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiLanguages.kt @@ -6,7 +6,7 @@ internal object OpenAiLanguages { val languageMap = linkedMapOf( Lang.ENGLISH to "English", - Lang.CHINESE to "Simplified Chinese", + Lang.CHINESE_SIMPLIFIED to "Simplified Chinese", Lang.CHINESE_TRADITIONAL to "Traditional Chinese", Lang.JAPANESE to "Japanese", Lang.KOREAN to "Korean", diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt index 49cd46f84..705730858 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt @@ -10,7 +10,7 @@ object YoudaoLanguageAdapter : BaseLanguageAdapter() { private val SUPPORTED_LANGUAGES: List = listOf( Lang.AUTO, - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, Lang.CHINESE_TRADITIONAL, Lang.ENGLISH, Lang.JAPANESE, @@ -33,7 +33,7 @@ object YoudaoLanguageAdapter : BaseLanguageAdapter() { override val supportedTargetLanguages: List = SUPPORTED_LANGUAGES override fun getAdaptedLanguages(): Map = mapOf( - "zh-CHS" to Lang.CHINESE, + "zh-CHS" to Lang.CHINESE_SIMPLIFIED, "zh-CHT" to Lang.CHINESE_TRADITIONAL, ) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/GoogleTTSPlayer.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/GoogleTTSPlayer.kt index 4b38cd5d3..891376f21 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/GoogleTTSPlayer.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/GoogleTTSPlayer.kt @@ -86,7 +86,7 @@ class GoogleTTSPlayer private constructor( private const val MAX_TEXT_LENGTH = 200 private val SUPPORTED_LANGUAGES: List = listOf( - Lang.CHINESE, Lang.ENGLISH, Lang.CHINESE_TRADITIONAL, Lang.ALBANIAN, Lang.ARABIC, Lang.ESTONIAN, + Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH, Lang.CHINESE_TRADITIONAL, Lang.ALBANIAN, Lang.ARABIC, Lang.ESTONIAN, Lang.ICELANDIC, Lang.POLISH, Lang.BOSNIAN, Lang.AFRIKAANS, Lang.DANISH, Lang.GERMAN, Lang.RUSSIAN, Lang.FRENCH, Lang.FINNISH, Lang.KHMER, Lang.KOREAN, Lang.DUTCH, Lang.CATALAN, Lang.CZECH, Lang.CROATIAN, Lang.LATIN, Lang.LATVIAN, Lang.ROMANIAN, Lang.MACEDONIAN, Lang.BENGALI, Lang.NEPALI, Lang.NORWEGIAN, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/microsoft/EdgeTTSVoiceManager.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/microsoft/EdgeTTSVoiceManager.kt index 5852a5159..76f501a59 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/microsoft/EdgeTTSVoiceManager.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/tts/microsoft/EdgeTTSVoiceManager.kt @@ -165,7 +165,7 @@ internal object EdgeTTSVoiceManager { BENGALI to "bn-IN", BULGARIAN to "bg-BG", CATALAN to "ca-ES", - CHINESE to "zh-CN", + CHINESE_SIMPLIFIED to "zh-CN", CHINESE_CANTONESE to "zh-HK", CHINESE_TRADITIONAL to "zh-CN", CROATIAN to "hr-HR", diff --git a/src/main/resources/messages/LanguageBundle.properties b/src/main/resources/messages/LanguageBundle.properties index af146c542..c2959b2d4 100644 --- a/src/main/resources/messages/LanguageBundle.properties +++ b/src/main/resources/messages/LanguageBundle.properties @@ -16,9 +16,10 @@ bulgarian=Bulgarian catalan=Catalan cebuano=Cebuano chichewa=Chichewa -chinese=Chinese (Simplified) +chinese=Chinese chinese.cantonese=Chinese (Cantonese) chinese.classical=Chinese (Classical) +chinese.simplified=Chinese (Simplified) chinese.traditional=Chinese (Traditional) corsican=Corsican croatian=Croatian diff --git a/src/main/resources/messages/LanguageBundle_ja.properties b/src/main/resources/messages/LanguageBundle_ja.properties index 07666463b..5f79d4f71 100644 --- a/src/main/resources/messages/LanguageBundle_ja.properties +++ b/src/main/resources/messages/LanguageBundle_ja.properties @@ -16,9 +16,10 @@ bulgarian=ブルガリア語 catalan=カタロニア語 cebuano=セブアノ語 chichewa=チェワ語 -chinese=中国語(簡体字) +chinese=中国語 chinese.cantonese=中国語(広東語) chinese.classical=中国語(漢文) +chinese.simplified=中国語(簡体字) chinese.traditional=中国語(繁体字) corsican=コルシカ語 croatian=クロアチア語 diff --git a/src/main/resources/messages/LanguageBundle_ko.properties b/src/main/resources/messages/LanguageBundle_ko.properties index 3c3c9961b..a58d06e6f 100644 --- a/src/main/resources/messages/LanguageBundle_ko.properties +++ b/src/main/resources/messages/LanguageBundle_ko.properties @@ -16,9 +16,10 @@ bulgarian=불가리아어 catalan=카탈로니아어 cebuano=세부아노어 chichewa=체와어 -chinese=중국어(간체) +chinese=중국어 chinese.cantonese=중국어(광동어) chinese.classical=중국어(전통) +chinese.simplified=중국어(간체) chinese.traditional=중국어(번체) corsican=코르시카어 croatian=크로아티아어 diff --git a/src/main/resources/messages/LanguageBundle_zh_CN.properties b/src/main/resources/messages/LanguageBundle_zh_CN.properties index 91fe94618..5b1691768 100644 --- a/src/main/resources/messages/LanguageBundle_zh_CN.properties +++ b/src/main/resources/messages/LanguageBundle_zh_CN.properties @@ -16,9 +16,10 @@ bulgarian=保加利亚语 catalan=加泰罗尼亚语 cebuano=宿务语 chichewa=齐切瓦语 -chinese=中文(简体) +chinese=中文 chinese.cantonese=粤语 chinese.classical=文言文 +chinese.simplified=中文(简体) chinese.traditional=中文(繁体) corsican=科西嘉语 croatian=克罗地亚语 diff --git a/src/test/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationUiTest.kt b/src/test/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationUiTest.kt index 8d060242c..5cd1eff98 100644 --- a/src/test/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationUiTest.kt +++ b/src/test/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationUiTest.kt @@ -14,8 +14,8 @@ fun main() = uiTest("Translation UI Test", 500, 300/*, true*/) { val ui = TranslationDialogUiImpl(null, TranslationDialogUiProvider.testProvider()) val mainPanel = ui.createMainPanel() - ui.sourceLangComboBox.model = LanguageListModel.simple(listOf(Lang.AUTO, Lang.ENGLISH, Lang.CHINESE)) - ui.targetLangComboBox.model = LanguageListModel.simple(listOf(Lang.CHINESE, Lang.ENGLISH)) + ui.sourceLangComboBox.model = LanguageListModel.simple(listOf(Lang.AUTO, Lang.ENGLISH, Lang.CHINESE_SIMPLIFIED)) + ui.targetLangComboBox.model = LanguageListModel.simple(listOf(Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH)) ui.initFonts(UI.FontPair(UI.defaultFont, UI.defaultFont.lessOn(2f))) @@ -26,7 +26,7 @@ fun main() = uiTest("Translation UI Test", 500, 300/*, true*/) { ui.targetTransliterationLabel.text = "Fānyì" val googleTranslation = createGoogleTranslation() - val translation = googleTranslation.toTranslation().copy(srcLang = Lang.CHINESE) + val translation = googleTranslation.toTranslation().copy(srcLang = Lang.CHINESE_SIMPLIFIED) ui.spellComponent.spell = "translation" ui.fixLangComponent.updateOnTranslation(translation) @@ -57,7 +57,7 @@ fun createDummyYoudaoTranslation(): YoudaoTranslation = YoudaoTranslation( fun createGoogleTranslation(): GoogleTranslation = GoogleTranslation( "translation", Lang.ENGLISH, - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, listOf(GTransSentence("translation", "翻译", 2), GTranslitSentence("transˈlāSH(ə)n", "Fānyì")), listOf( GDict( From bb34bff62ab7afd9a4282f553713cd8bda69138a Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Mon, 2 Sep 2024 16:54:55 +0800 Subject: [PATCH 4/7] Update DeepL supported languages list issue: #5947 --- .../translate/trans/deepl/DeeplService.kt | 12 +-- ...eAdapter.kt => DeeplSupportedLanguages.kt} | 78 ++++++++++++++----- .../translate/trans/deepl/DeeplTranslator.kt | 4 +- 3 files changed, 67 insertions(+), 27 deletions(-) rename src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/{DeeplLanguageAdapter.kt => DeeplSupportedLanguages.kt} (61%) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplService.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplService.kt index 414565c6b..cfed28d03 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplService.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplService.kt @@ -13,7 +13,7 @@ import com.intellij.util.io.RequestBuilder class DeeplService(var authKey: String) { /** - * Determines if the given [DeepL Authentication Key][authKey] belongs to an API Free account. + * Determines if the given [DeepL Authentication Key][authKey] belongs to an API-Free account. */ val isFreeAccount: Boolean get() = isFreeAccountAuthKey(authKey) @@ -27,7 +27,7 @@ class DeeplService(var authKey: String) { private fun RequestBuilder.auth() { userAgent(Http.PLUGIN_USER_AGENT) // Authentication method should be header-based authentication, - // auth-key will leak into the log file if it is authenticated as a parameter. + // the auth-key will leak into the log file if it is authenticated as a parameter. tuner { it.setRequestProperty("Authorization", "DeepL-Auth-Key $authKey") } } @@ -36,11 +36,11 @@ class DeeplService(var authKey: String) { */ fun translate(text: String, sourceLang: Lang, targetLang: Lang, isDocument: Boolean): String { val params: LinkedHashMap = linkedMapOf( - "target_lang" to targetLang.deeplLanguageCode, + "target_lang" to targetLang.deeplLanguageCodeForTarget, "text" to text ) if (sourceLang !== Lang.AUTO) { - params["source_lang"] = sourceLang.deeplLanguageCode + params["source_lang"] = sourceLang.deeplLanguageCodeForSource } if (isDocument) { params["tag_handling"] = "html" @@ -80,10 +80,10 @@ class DeeplService(var authKey: String) { private const val DEEPL_SERVER_URL_PRO = "https://api.deepl.com" /** - * Determines if the given [DeepL Authentication Key][authKey] belongs to an API Free account. + * Determines if the given [DeepL Authentication Key][authKey] belongs to an API-Free account. * * @param authKey DeepL Authentication Key as found in your [DeepL account](https://www.deepl.com/pro-account/). - * @return `true` if the Authentication Key belongs to an API Free account, otherwise `false`. + * @return `true` if the Authentication Key belongs to an API-Free account, otherwise `false`. */ fun isFreeAccountAuthKey(authKey: String): Boolean = authKey.endsWith(":fx") } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt similarity index 61% rename from src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplLanguageAdapter.kt rename to src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt index 360c59260..425274d2a 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt @@ -3,30 +3,36 @@ package cn.yiiguxing.plugin.translate.trans.deepl import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang + /** - * Language adapter for DeepL Translator. + * Supported languages for DeepL Translator. */ -object DeeplLanguageAdapter : BaseLanguageAdapter() { - - override val supportedSourceLanguages: List = listOf( +object DeeplSupportedLanguages { + /** + * The supported source languages. + */ + val sourceLanguages: List = listOf( Lang.AUTO, + Lang.ARABIC, Lang.BULGARIAN, Lang.CHINESE, Lang.CZECH, Lang.DANISH, Lang.DUTCH, - Lang.GERMAN, - Lang.GREEK, Lang.ENGLISH, Lang.ESTONIAN, Lang.FINNISH, Lang.FRENCH, + Lang.GERMAN, + Lang.GREEK, Lang.HUNGARIAN, + Lang.INDONESIAN, Lang.ITALIAN, Lang.JAPANESE, Lang.KOREAN, Lang.LATVIAN, Lang.LITHUANIAN, + Lang.NORWEGIAN, Lang.POLISH, Lang.PORTUGUESE, Lang.ROMANIAN, @@ -35,86 +41,120 @@ object DeeplLanguageAdapter : BaseLanguageAdapter() { Lang.SLOVENIAN, Lang.SPANISH, Lang.SWEDISH, + Lang.TURKISH, Lang.UKRAINIAN, ) - override val supportedTargetLanguages: List = listOf( + /** + * The supported target languages. + */ + val targetLanguages: List = listOf( + Lang.ARABIC, Lang.BULGARIAN, - Lang.CHINESE, + Lang.CHINESE_SIMPLIFIED, + Lang.CHINESE_TRADITIONAL, Lang.CZECH, Lang.DANISH, Lang.DUTCH, - Lang.GERMAN, - Lang.GREEK, - Lang.ENGLISH, Lang.ENGLISH_AMERICAN, Lang.ENGLISH_BRITISH, Lang.ESTONIAN, Lang.FINNISH, Lang.FRENCH, + Lang.GERMAN, + Lang.GREEK, Lang.HUNGARIAN, + Lang.INDONESIAN, Lang.ITALIAN, Lang.JAPANESE, Lang.KOREAN, Lang.LATVIAN, Lang.LITHUANIAN, + Lang.NORWEGIAN, Lang.POLISH, Lang.PORTUGUESE, Lang.PORTUGUESE_BRAZILIAN, - Lang.PORTUGUESE_PORTUGUESE, Lang.ROMANIAN, Lang.RUSSIAN, Lang.SLOVAK, Lang.SLOVENIAN, Lang.SPANISH, Lang.SWEDISH, + Lang.TURKISH, Lang.UKRAINIAN, ) +} + +private val adapter = object : BaseLanguageAdapter() { + override val supportedSourceLanguages: List = DeeplSupportedLanguages.sourceLanguages + + override val supportedTargetLanguages: List = DeeplSupportedLanguages.targetLanguages override fun getAdaptedLanguages(): Map = mapOf( + "AR" to Lang.ARABIC, "BG" to Lang.BULGARIAN, "ZH" to Lang.CHINESE, + "ZH-HANS" to Lang.CHINESE_SIMPLIFIED, + "ZH-HANT" to Lang.CHINESE_TRADITIONAL, "CS" to Lang.CZECH, "DA" to Lang.DANISH, "NL" to Lang.DUTCH, - "DE" to Lang.GERMAN, - "EL" to Lang.GREEK, "EN" to Lang.ENGLISH, "EN-US" to Lang.ENGLISH_AMERICAN, "EN-GB" to Lang.ENGLISH_BRITISH, "ET" to Lang.ESTONIAN, "FI" to Lang.FINNISH, "FR" to Lang.FRENCH, + "DE" to Lang.GERMAN, + "EL" to Lang.GREEK, "HU" to Lang.HUNGARIAN, "IT" to Lang.ITALIAN, + "ID" to Lang.INDONESIAN, "JA" to Lang.JAPANESE, "KO" to Lang.KOREAN, "LV" to Lang.LATVIAN, "LT" to Lang.LITHUANIAN, + "NB" to Lang.NORWEGIAN, "PL" to Lang.POLISH, + + // PORTUGUESE is ambiguous, and the regions it + // represents differ between the source and target languages. "PT" to Lang.PORTUGUESE, + "PT-PT" to Lang.PORTUGUESE, + "PT-BR" to Lang.PORTUGUESE_BRAZILIAN, - "PT-PT" to Lang.PORTUGUESE_PORTUGUESE, "RO" to Lang.ROMANIAN, "RU" to Lang.RUSSIAN, "SK" to Lang.SLOVAK, "SL" to Lang.SLOVENIAN, "ES" to Lang.SPANISH, "SV" to Lang.SWEDISH, + "TR" to Lang.TURKISH, "UK" to Lang.UKRAINIAN, ) } +/** + * Source Language Code for DeepL Translator. + */ +val Lang.deeplLanguageCodeForSource: String + get() = when (this) { + Lang.PORTUGUESE -> "PT" + else -> adapter.getLanguageCode(this) + } /** - * Language code for DeepL Translator. + * Target Language Code for DeepL Translator. */ -val Lang.deeplLanguageCode: String - get() = DeeplLanguageAdapter.getLanguageCode(this) +val Lang.deeplLanguageCodeForTarget: String + get() = when (this) { + Lang.PORTUGUESE -> "PT-PT" + else -> adapter.getLanguageCode(this) + } /** * Returns the [language][Lang] for the specified DeepL Translator language [code]. */ fun Lang.Companion.fromDeeplLanguageCode(code: String): Lang { - return DeeplLanguageAdapter.getLanguage(code) + return adapter.getLanguage(code) } \ No newline at end of file diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplTranslator.kt index 344323c16..84a6c24f3 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplTranslator.kt @@ -33,9 +33,9 @@ object DeeplTranslator : AbstractTranslator(), DocumentationTranslator { override val primaryLanguage: Lang get() = DEEPL.primaryLanguage - override val supportedSourceLanguages: List = DeeplLanguageAdapter.supportedSourceLanguages + override val supportedSourceLanguages: List = DeeplSupportedLanguages.sourceLanguages - override val supportedTargetLanguages: List = DeeplLanguageAdapter.supportedTargetLanguages + override val supportedTargetLanguages: List = DeeplSupportedLanguages.targetLanguages override fun checkConfiguration(force: Boolean): Boolean { if (force || !DeeplCredential.isAuthKeySet) { From 3555549c6c016a030347e81704582b8746774bf3 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Wed, 4 Sep 2024 10:41:12 +0800 Subject: [PATCH 5/7] Refactor supported languages --- .../cn/yiiguxing/plugin/translate/Contract.kt | 5 ++--- .../plugin/translate/TranslationPresenter.kt | 5 +++-- .../plugin/translate/trans/LanguageAdapter.kt | 10 --------- .../translate/trans/SupportedLanguages.kt | 21 +++++++++++++++++++ .../translate/trans/ali/AliLanguageAdapter.kt | 7 ++++--- .../translate/trans/ali/AliTranslator.kt | 4 ++-- .../trans/baidu/BaiduLanguageAdapter.kt | 7 ++++--- .../translate/trans/baidu/BaiduTranslator.kt | 4 ++-- .../trans/deepl/DeeplSupportedLanguages.kt | 11 ++++------ .../trans/google/GoogleLanguageAdapter.kt | 8 +++---- .../trans/google/GoogleTranslator.kt | 4 ++-- .../microsoft/MicrosoftLanguageAdapter.kt | 8 +++---- .../trans/microsoft/MicrosoftTranslator.kt | 4 ++-- .../trans/youdao/YoudaoLanguageAdapter.kt | 7 ++++--- .../trans/youdao/YoudaoTranslator.kt | 4 ++-- 15 files changed, 60 insertions(+), 49 deletions(-) create mode 100644 src/main/kotlin/cn/yiiguxing/plugin/translate/trans/SupportedLanguages.kt diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/Contract.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/Contract.kt index 44c9d00f6..04fb28a68 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/Contract.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/Contract.kt @@ -4,12 +4,11 @@ package cn.yiiguxing.plugin.translate import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguagesData import cn.yiiguxing.plugin.translate.trans.Translation import cn.yiiguxing.plugin.translate.trans.Translator import com.intellij.openapi.Disposable -data class SupportedLanguages(val source: List, val target: List) - interface Presenter { val translator: Translator @@ -27,7 +26,7 @@ interface Presenter { /** * 已支持的语言 */ - val supportedLanguages: SupportedLanguages + val supportedLanguages: SupportedLanguagesData /** * 检测指定的源语言是否被支持 diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/TranslationPresenter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/TranslationPresenter.kt index 9bbf79cad..ee890261e 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/TranslationPresenter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/TranslationPresenter.kt @@ -23,9 +23,9 @@ class TranslationPresenter(private val view: View, private val recordHistory: Bo override val primaryLanguage: Lang get() = translator.primaryLanguage - override val supportedLanguages: SupportedLanguages + override val supportedLanguages: SupportedLanguagesData get() = with(translator) { - SupportedLanguages(supportedSourceLanguages, supportedTargetLanguages) + SupportedLanguagesData(supportedSourceLanguages, supportedTargetLanguages) } override fun isSupportedSourceLanguage(sourceLanguage: Lang): Boolean { @@ -44,6 +44,7 @@ class TranslationPresenter(private val view: View, private val recordHistory: Bo return when (settings.targetLanguageSelection) { DEFAULT -> Lang.AUTO.takeIf { isSupportedTargetLanguage(it) } ?: if (text.isEmpty() || text.any(NON_LATIN_CONDITION)) Lang.ENGLISH else primaryLanguage + PRIMARY_LANGUAGE -> primaryLanguage LAST -> states.lastLanguages.target.takeIf { isSupportedTargetLanguage(it) } ?: primaryLanguage } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/LanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/LanguageAdapter.kt index effb3bbe3..1619d5338 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/LanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/LanguageAdapter.kt @@ -5,16 +5,6 @@ package cn.yiiguxing.plugin.translate.trans */ interface LanguageAdapter { - /** - * List of supported source languages. - */ - val supportedSourceLanguages: List - - /** - * List of supported target languages. - */ - val supportedTargetLanguages: List - /** * Returns the [language][Lang] corresponding to the given [code]. */ diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/SupportedLanguages.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/SupportedLanguages.kt new file mode 100644 index 000000000..b9633de43 --- /dev/null +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/SupportedLanguages.kt @@ -0,0 +1,21 @@ +package cn.yiiguxing.plugin.translate.trans + +/** + * Supported languages. + */ +interface SupportedLanguages { + /** + * The supported source languages. + */ + val sourceLanguages: List + + /** + * The supported target languages. + */ + val targetLanguages: List +} + +data class SupportedLanguagesData( + override val sourceLanguages: List, + override val targetLanguages: List +) : SupportedLanguages \ No newline at end of file diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt index 838978688..04d4cbef6 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliLanguageAdapter.kt @@ -2,13 +2,14 @@ package cn.yiiguxing.plugin.translate.trans.ali import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Language adapter for Ali Translator. */ -object AliLanguageAdapter : BaseLanguageAdapter() { +object AliLanguageAdapter : BaseLanguageAdapter(), SupportedLanguages { - override val supportedSourceLanguages: List = listOf( + override val sourceLanguages: List = listOf( Lang.AUTO, Lang.CHINESE_SIMPLIFIED, Lang.CHINESE_TRADITIONAL, @@ -30,7 +31,7 @@ object AliLanguageAdapter : BaseLanguageAdapter() { Lang.HINDI ) - override val supportedTargetLanguages: List = listOf( + override val targetLanguages: List = listOf( Lang.CHINESE_SIMPLIFIED, Lang.ENGLISH, Lang.JAPANESE, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslator.kt index a72d5d678..8e4e64ab4 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslator.kt @@ -47,9 +47,9 @@ object AliTranslator : AbstractTranslator(), DocumentationTranslator { override val primaryLanguage: Lang get() = ALI.primaryLanguage - override val supportedSourceLanguages: List = AliLanguageAdapter.supportedSourceLanguages + override val supportedSourceLanguages: List = AliLanguageAdapter.sourceLanguages - override val supportedTargetLanguages: List = AliLanguageAdapter.supportedTargetLanguages + override val supportedTargetLanguages: List = AliLanguageAdapter.targetLanguages override fun checkConfiguration(force: Boolean): Boolean { if (force || diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt index ecc5a2d54..0854a9bcb 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduLanguageAdapter.kt @@ -2,11 +2,12 @@ package cn.yiiguxing.plugin.translate.trans.baidu import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Language adapter for Baidu Translator. */ -object BaiduLanguageAdapter : BaseLanguageAdapter() { +object BaiduLanguageAdapter : BaseLanguageAdapter(), SupportedLanguages { /** 通用版支持的语言列表 */ private val SUPPORTED_LANGUAGES: List = listOf( @@ -123,11 +124,11 @@ object BaiduLanguageAdapter : BaseLanguageAdapter() { Lang.ARMENIAN, ) - override val supportedSourceLanguages: List = SUPPORTED_LANGUAGES + override val sourceLanguages: List = SUPPORTED_LANGUAGES .toMutableList() .apply { add(0, Lang.AUTO) } - override val supportedTargetLanguages: List = SUPPORTED_LANGUAGES + override val targetLanguages: List = SUPPORTED_LANGUAGES override fun getAdaptedLanguages(): Map = mapOf( "afr" to Lang.AFRIKAANS, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduTranslator.kt index 87fd94bd1..f1446f405 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/baidu/BaiduTranslator.kt @@ -42,9 +42,9 @@ object BaiduTranslator : AbstractTranslator() { override val primaryLanguage: Lang get() = BAIDU.primaryLanguage - override val supportedSourceLanguages: List = BaiduLanguageAdapter.supportedSourceLanguages + override val supportedSourceLanguages: List = BaiduLanguageAdapter.sourceLanguages - override val supportedTargetLanguages: List = BaiduLanguageAdapter.supportedTargetLanguages + override val supportedTargetLanguages: List = BaiduLanguageAdapter.targetLanguages private val errorMessageMap: Map by lazy { mapOf( diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt index 425274d2a..7ed064984 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/deepl/DeeplSupportedLanguages.kt @@ -2,16 +2,17 @@ package cn.yiiguxing.plugin.translate.trans.deepl import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Supported languages for DeepL Translator. */ -object DeeplSupportedLanguages { +object DeeplSupportedLanguages : SupportedLanguages { /** * The supported source languages. */ - val sourceLanguages: List = listOf( + override val sourceLanguages: List = listOf( Lang.AUTO, Lang.ARABIC, Lang.BULGARIAN, @@ -48,7 +49,7 @@ object DeeplSupportedLanguages { /** * The supported target languages. */ - val targetLanguages: List = listOf( + override val targetLanguages: List = listOf( Lang.ARABIC, Lang.BULGARIAN, Lang.CHINESE_SIMPLIFIED, @@ -86,10 +87,6 @@ object DeeplSupportedLanguages { } private val adapter = object : BaseLanguageAdapter() { - override val supportedSourceLanguages: List = DeeplSupportedLanguages.sourceLanguages - - override val supportedTargetLanguages: List = DeeplSupportedLanguages.targetLanguages - override fun getAdaptedLanguages(): Map = mapOf( "AR" to Lang.ARABIC, "BG" to Lang.BULGARIAN, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt index b7e4d0369..e73ee08d7 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleLanguageAdapter.kt @@ -2,11 +2,12 @@ package cn.yiiguxing.plugin.translate.trans.google import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Language adapter for Google Translator. */ -object GoogleLanguageAdapter : BaseLanguageAdapter() { +object GoogleLanguageAdapter : BaseLanguageAdapter(), SupportedLanguages { private val UNSUPPORTED_LANGUAGES: Set = setOf( Lang.ASSAMESE, @@ -36,10 +37,9 @@ object GoogleLanguageAdapter : BaseLanguageAdapter() { override fun getAdaptedLanguages(): Map = mapOf() - override val supportedSourceLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES).toList() + override val sourceLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES).toList() - override val supportedTargetLanguages: List = - (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES - Lang.AUTO).toList() + override val targetLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES - Lang.AUTO).toList() } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleTranslator.kt index d928e4f8e..aadd7fdf8 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/google/GoogleTranslator.kt @@ -44,9 +44,9 @@ object GoogleTranslator : AbstractTranslator(), DocumentationTranslator { override val primaryLanguage: Lang get() = GOOGLE.primaryLanguage - override val supportedSourceLanguages: List = GoogleLanguageAdapter.supportedSourceLanguages + override val supportedSourceLanguages: List = GoogleLanguageAdapter.sourceLanguages - override val supportedTargetLanguages: List = GoogleLanguageAdapter.supportedTargetLanguages + override val supportedTargetLanguages: List = GoogleLanguageAdapter.targetLanguages override fun doTranslate(text: String, srcLang: Lang, targetLang: Lang): Translation { diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt index 650ffdc09..c49623579 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftLanguageAdapter.kt @@ -2,11 +2,12 @@ package cn.yiiguxing.plugin.translate.trans.microsoft import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Language adapter for Microsoft Translator. */ -internal object MicrosoftLanguageAdapter : BaseLanguageAdapter() { +internal object MicrosoftLanguageAdapter : BaseLanguageAdapter(), SupportedLanguages { private val UNSUPPORTED_LANGUAGES: Set = setOf( Lang.BELARUSIAN, @@ -57,10 +58,9 @@ internal object MicrosoftLanguageAdapter : BaseLanguageAdapter() { "pt" to Lang.PORTUGUESE_BRAZILIAN, ) - override val supportedSourceLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES).toList() + override val sourceLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES).toList() - override val supportedTargetLanguages: List = - (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES - Lang.AUTO).toList() + override val targetLanguages: List = (Lang.sortedLanguages - UNSUPPORTED_LANGUAGES - Lang.AUTO).toList() } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslator.kt index 31b69d758..a459759bb 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslator.kt @@ -28,8 +28,8 @@ object MicrosoftTranslator : AbstractTranslator(), DocumentationTranslator { override val intervalLimit: Int = MICROSOFT.intervalLimit override val contentLengthLimit: Int = MICROSOFT.contentLengthLimit override val primaryLanguage: Lang get() = MICROSOFT.primaryLanguage - override val supportedSourceLanguages: List = MicrosoftLanguageAdapter.supportedSourceLanguages - override val supportedTargetLanguages: List = MicrosoftLanguageAdapter.supportedTargetLanguages + override val supportedSourceLanguages: List = MicrosoftLanguageAdapter.sourceLanguages + override val supportedTargetLanguages: List = MicrosoftLanguageAdapter.targetLanguages override fun doTranslate(text: String, srcLang: Lang, targetLang: Lang): Translation { if (!targetLang.isExplicit()) { diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt index 705730858..5c6906d97 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoLanguageAdapter.kt @@ -2,11 +2,12 @@ package cn.yiiguxing.plugin.translate.trans.youdao import cn.yiiguxing.plugin.translate.trans.BaseLanguageAdapter import cn.yiiguxing.plugin.translate.trans.Lang +import cn.yiiguxing.plugin.translate.trans.SupportedLanguages /** * Language adapter for Youdao Translator. */ -object YoudaoLanguageAdapter : BaseLanguageAdapter() { +object YoudaoLanguageAdapter : BaseLanguageAdapter(), SupportedLanguages { private val SUPPORTED_LANGUAGES: List = listOf( Lang.AUTO, @@ -28,9 +29,9 @@ object YoudaoLanguageAdapter : BaseLanguageAdapter() { Lang.ARABIC, ) - override val supportedSourceLanguages: List = SUPPORTED_LANGUAGES + override val sourceLanguages: List = SUPPORTED_LANGUAGES - override val supportedTargetLanguages: List = SUPPORTED_LANGUAGES + override val targetLanguages: List = SUPPORTED_LANGUAGES override fun getAdaptedLanguages(): Map = mapOf( "zh-CHS" to Lang.CHINESE_SIMPLIFIED, diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoTranslator.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoTranslator.kt index 679af8f16..52591c292 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoTranslator.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/youdao/YoudaoTranslator.kt @@ -44,9 +44,9 @@ object YoudaoTranslator : AbstractTranslator(), DocumentationTranslator { override val primaryLanguage: Lang get() = YOUDAO.primaryLanguage - override val supportedSourceLanguages: List = YoudaoLanguageAdapter.supportedSourceLanguages + override val supportedSourceLanguages: List = YoudaoLanguageAdapter.sourceLanguages - override val supportedTargetLanguages: List = YoudaoLanguageAdapter.supportedTargetLanguages + override val supportedTargetLanguages: List = YoudaoLanguageAdapter.targetLanguages private val errorMessageMap: Map by lazy { mapOf( From c2cb2fd81a98021f327f5ba2463ad707729fd1cf Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Tue, 17 Sep 2024 13:03:16 +0800 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1925d3f9a..04c157bdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## [Unreleased] +- DeepL Translator now supports languages such as Chinese Traditional. +- User interaction experience optimization and improvement. +- Bug fixes. +- DeepL 翻译现已支持繁体中文等语言 +- 用户交互体验优化与改进 +- Bug 修复 + ## [3.6.4] (2024/07/23) - The GPT-4o mini is now available in the OpenAI Translator engine. From 1380a7a62e3d9e49ec75cc4364c9930536b8c8bb Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Tue, 17 Sep 2024 13:03:23 +0800 Subject: [PATCH 7/7] :triangular_flag_on_post: v3.6.5 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ed2ad850b..36abb2ab4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ pluginGroup = cn.yiiguxing.plugin.translate pluginRepositoryUrl = https://github.com/YiiGuxing/TranslationPlugin # SemVer format -> https://semver.org -pluginMajorVersion = 3.6.4 +pluginMajorVersion = 3.6.5 pluginPreReleaseVersion = pluginBuildMetadata = autoSnapshotVersion = true