From 8e1d85ba718464ca554c9328498a70105ad8a500 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 15 Oct 2023 11:39:51 +0000 Subject: [PATCH 01/16] :rocket: v3.5.5 [skip ci] (cherry picked from commit 1a1cd906cccbad16f47ca1aea23414b0cb5e6a4b) --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 017999a03..50adba065 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Translation Plugin Changelog ## [Unreleased] + +## [3.5.5] (2023/10/15) + - Added support for RustRover and the new Rust plugin. - DeepL Translator now supports Ukrainian and Korean. - Compatible with 2023.3. @@ -436,7 +439,8 @@ - 支持单词拆分。翻译变量名或方法名时更方便 - Bug修复 -[Unreleased]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.4...HEAD +[Unreleased]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.5...HEAD +[3.5.5]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.4...v3.5.5 [3.5.4]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.3...v3.5.4 [3.5.3]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.2...v3.5.3 [3.5.2]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.1...v3.5.2 From 13d86a224f3043b78bb339acd1319317668cfe6f Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Mon, 16 Oct 2023 17:01:35 +0800 Subject: [PATCH 02/16] Fix the issue of not being able to share data context between Swing events Fix: #4576 --- .../translate/action/SwitchTranslationEngineAction.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/action/SwitchTranslationEngineAction.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/action/SwitchTranslationEngineAction.kt index f50b57180..a3ca1555e 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/action/SwitchTranslationEngineAction.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/action/SwitchTranslationEngineAction.kt @@ -6,11 +6,9 @@ import cn.yiiguxing.plugin.translate.util.concurrent.errorOnUiThread import cn.yiiguxing.plugin.translate.util.concurrent.expireWith import cn.yiiguxing.plugin.translate.util.concurrent.finishOnUiThread import cn.yiiguxing.plugin.translate.util.concurrent.successOnUiThread +import com.intellij.ide.DataManager import com.intellij.openapi.Disposable -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.DefaultActionGroup -import com.intellij.openapi.actionSystem.PopupAction -import com.intellij.openapi.actionSystem.Presentation +import com.intellij.openapi.actionSystem.* import com.intellij.openapi.actionSystem.ex.ComboBoxAction import com.intellij.openapi.application.ModalityState import com.intellij.openapi.project.DumbAware @@ -64,12 +62,14 @@ class SwitchTranslationEngineAction : ComboBoxAction(), DumbAware, PopupAction { } isActionPerforming = true + val component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT) val expireDisposable = getDisposable() runAsync { TranslationEngineActionGroup() } .expireWith(expireDisposable) .successOnUiThread { group -> if (isActionPerforming && !project.isDisposed) { - group.createActionPopup(e.dataContext).showCenteredInCurrentWindow(project) + val dataContext = DataManager.getInstance().getDataContext(component) + group.createActionPopup(dataContext).showCenteredInCurrentWindow(project) } } .finishOnUiThread(ModalityState.any()) { isActionPerforming = false } From 84db6b53ea1398b5413626f4ac5cf5d19ec09c81 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 23:54:22 +0000 Subject: [PATCH 03/16] Bump org.jsoup:jsoup from 1.16.1 to 1.16.2 Bumps [org.jsoup:jsoup](https://github.com/jhy/jsoup) from 1.16.1 to 1.16.2. - [Release notes](https://github.com/jhy/jsoup/releases) - [Changelog](https://github.com/jhy/jsoup/blob/master/CHANGES) - [Commits](https://github.com/jhy/jsoup/compare/jsoup-1.16.1...jsoup-1.16.2) --- updated-dependencies: - dependency-name: org.jsoup:jsoup dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e2ec47a0e..0583c1164 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # libraries -jsoup = "1.16.1" +jsoup = "1.16.2" dbutils = "1.8.1" mp3spi = "1.9.5.4" junit = "4.13.2" From 1f12fe23c2f122e1e6242c29ebd6d8805342800f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 23:14:20 +0000 Subject: [PATCH 04/16] Bump org.jetbrains.kotlin.jvm from 1.9.10 to 1.9.20 Bumps [org.jetbrains.kotlin.jvm](https://github.com/JetBrains/kotlin) from 1.9.10 to 1.9.20. - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/master/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/commits) --- updated-dependencies: - dependency-name: org.jetbrains.kotlin.jvm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0583c1164..68bb397ab 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,7 +6,7 @@ mp3spi = "1.9.5.4" junit = "4.13.2" # plugins -kotlin = "1.9.10" +kotlin = "1.9.20" kover = "0.7.4" qodana = "0.1.13" changelog = "2.2.0" From 8f1bc9d8f582dfa983f069da7937b090e6c92fea Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Thu, 2 Nov 2023 17:48:23 +0800 Subject: [PATCH 05/16] Simplify the code for the `LruCache` class --- .../plugin/translate/util/LruCache.kt | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/LruCache.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/LruCache.kt index 50f8c8024..b7a9e9dc2 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/LruCache.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/LruCache.kt @@ -170,9 +170,7 @@ open class LruCache(maxSize: Int) { val previous: V? = synchronized(this) { putCount++ size += safeSizeOf(key, value) - map.put(key, value)?.apply { - size -= safeSizeOf(key, this@apply) - } + map.put(key, value)?.also { size -= safeSizeOf(key, it) } } previous?.let { entryRemoved(false, key, it, value) @@ -183,17 +181,15 @@ open class LruCache(maxSize: Int) { } /** - * Remove the eldest entries until the total of remaining entries is at or - * below the requested size. + * Remove the eldest entries until the total of remaining entries is at or below the requested size. * - * @param maxSize the maximum size of the cache before returning. May be -1 - * to evict even 0-sized elements. + * @param maxSize the maximum size of the cache before returning. Maybe -1 to evict even 0-sized elements. */ fun trimToSize(maxSize: Int) { while (true) { val toEvict = synchronized(this) { check(!(size < 0 || map.isEmpty() && size != 0)) { - javaClass.name + ".sizeOf() is reporting inconsistent results!" + "${javaClass.name}.sizeOf() is reporting inconsistent results! size=$size." } if (size <= maxSize || map.isEmpty()) { @@ -217,14 +213,10 @@ open class LruCache(maxSize: Int) { * @return the previous value mapped by [key]. */ fun remove(key: K & Any): V? { - val previous: V? = synchronized(this) { - map.remove(key)?.apply { - size -= safeSizeOf(key, this@apply) - } - } - - return previous?.apply { - entryRemoved(false, key, this@apply, null) + return synchronized(this) { + map.remove(key)?.also { previous -> size -= safeSizeOf(key, previous) } + }?.also { previous -> + entryRemoved(false, key, previous, null) } } @@ -246,8 +238,8 @@ open class LruCache(maxSize: Int) { } if (removed.isNotEmpty()) { - removed.forEach { - entryRemoved(false, it.key, it.value, null) + removed.forEach { (key, value) -> + entryRemoved(false, key, value, null) } } From d128be67d714d97caaf98f76899e06dd0fb46d83 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Mon, 13 Nov 2023 15:44:16 +0800 Subject: [PATCH 06/16] Fix illegal parameters for Youdao Translator Fix: #4739 --- .../plugin/translate/trans/youdao/YoudaoTranslator.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 6b103f05b..a0532342e 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 @@ -139,17 +139,16 @@ object YoudaoTranslator : AbstractTranslator(), DocumentationTranslator { srcLang: Lang, targetLang: Lang ): Document = checkError { - documentation.translateBody { bodyHTML -> - translateDocumentation(bodyHTML, srcLang, targetLang) - } + // Youdao does not support auto detection language for documentation translation + val fixedSrcLang = srcLang.takeIf { it != Lang.AUTO } ?: Lang.ENGLISH + val fixedTargetLang = targetLang.takeIf { it != Lang.AUTO } ?: super.defaultLangForLocale + documentation.translateBody { bodyHTML -> translateDocumentation(bodyHTML, fixedSrcLang, fixedTargetLang) } } private fun translateDocumentation(documentation: String, srcLang: Lang, targetLang: Lang): String { - // Youdao does not support auto detection target language for documentation translation - val fixedTargetLang = targetLang.takeIf { it != Lang.AUTO } ?: super.defaultLangForLocale val client = SimpleTranslateClient(this, ::callForDocumentation, ::parseTranslationForDocumentation) client.updateCacheKey { it.update("DOCUMENTATION".toByteArray()) } - return client.execute(documentation, srcLang, fixedTargetLang).translation ?: "" + return client.execute(documentation, srcLang, targetLang).translation ?: "" } private fun callForDocumentation(text: String, srcLang: Lang, targetLang: Lang): String { From 413e6cc04c7417c66b15f4f3817a17d78c34124c Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Mon, 13 Nov 2023 15:50:45 +0800 Subject: [PATCH 07/16] Update message bundle --- src/main/resources/messages/TranslationBundle.properties | 2 +- src/main/resources/messages/TranslationBundle_ja.properties | 2 +- src/main/resources/messages/TranslationBundle_ko.properties | 2 +- src/main/resources/messages/TranslationBundle_zh.properties | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/messages/TranslationBundle.properties b/src/main/resources/messages/TranslationBundle.properties index dcc29c78f..834d06553 100644 --- a/src/main/resources/messages/TranslationBundle.properties +++ b/src/main/resources/messages/TranslationBundle.properties @@ -347,6 +347,6 @@ youdao.settings.dialog.hint=You may need to create a translation applicati Youdao Console \ to obtain an Application ID and Application Key, and enable these services: \ Text Translation, \ - Rich Text Translation and \ + Webpage Translation and \ Domain-specific Translation \ (optional) \ No newline at end of file diff --git a/src/main/resources/messages/TranslationBundle_ja.properties b/src/main/resources/messages/TranslationBundle_ja.properties index 8c0ac0f43..d71496b65 100644 --- a/src/main/resources/messages/TranslationBundle_ja.properties +++ b/src/main/resources/messages/TranslationBundle_ja.properties @@ -347,6 +347,6 @@ youdao.settings.dialog.hint=Application IDとApplication Keyを取得し Youdao Console \ ページで翻訳アプリケーションを作成する必要があるかもしれません: \ テキスト翻訳、\ - リッチテキスト翻訳、および \ + ウェブページの翻訳、および \ ドメイン特化翻訳 \ (オプション) \ No newline at end of file diff --git a/src/main/resources/messages/TranslationBundle_ko.properties b/src/main/resources/messages/TranslationBundle_ko.properties index 0790f1c93..47b6baae6 100644 --- a/src/main/resources/messages/TranslationBundle_ko.properties +++ b/src/main/resources/messages/TranslationBundle_ko.properties @@ -347,6 +347,6 @@ youdao.settings.dialog.hint=Application ID와 Application Key를 얻기 Youdao Console \ 페이지에서 번역 애플리케이션을 생성해야 할 수도 있으며, 다음 서비스를 활성화해야 합니다: \ 텍스트 번역, \ - 리치 텍스트 번역 \ + 웹페이지 번역 \ 그리고 도메인 특화 번역 \ (선택 사항) \ No newline at end of file diff --git a/src/main/resources/messages/TranslationBundle_zh.properties b/src/main/resources/messages/TranslationBundle_zh.properties index 5065b3900..e79f207dc 100644 --- a/src/main/resources/messages/TranslationBundle_zh.properties +++ b/src/main/resources/messages/TranslationBundle_zh.properties @@ -347,6 +347,6 @@ youdao.settings.dialog.hint=您可能需要在您的\ 有道智云控制台\ 页面创建一个翻译应用以获取应用ID和应用秘钥,并开通这些服务:\ 文本翻译、\ - 富文本翻译 和 \ + 网页翻译 和 \ 领域化翻译\ (可选) \ No newline at end of file From 4f0459c3070a7ec00bf81b3b1fc18d84452da592 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 12:38:14 +0800 Subject: [PATCH 08/16] Clean up --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6fc792a8f..0bbd44e3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,7 @@ plugins { fun properties(key: String) = providers.gradleProperty(key) fun environment(key: String) = providers.environmentVariable(key) -fun dateValue(pattern: String) = LocalDate.now(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ofPattern(pattern)) +fun dateValue(pattern: String): String = LocalDate.now(ZoneId.of("Asia/Shanghai")).format(DateTimeFormatter.ofPattern(pattern)) val autoSnapshotVersionEnv: Provider = environment("AUTO_SNAPSHOT_VERSION").map(String::toBoolean).orElse(true) val snapshotVersionPart: Provider = properties("autoSnapshotVersion") From 5c7e2ab6fca97f04df4ea52eabd35f23a232c7d2 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 15:12:11 +0800 Subject: [PATCH 09/16] Fix `IllegalComponentStateException`: component must be showing on the screen to determine its location --- .../yiiguxing/plugin/translate/ui/TranslationFailedComponent.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationFailedComponent.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationFailedComponent.kt index 90f860b3d..57437fbe3 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationFailedComponent.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationFailedComponent.kt @@ -109,7 +109,7 @@ class TranslationFailedComponent : JPanel(), Disposable { runAsync { TranslationEngineActionGroup() } .expireWith(this) .successOnUiThread(widgetRef) { widget, group -> - val button = widget.optionButton + val button = widget.optionButton.takeIf { it.isShowing } ?: return@successOnUiThread var offsetLeft: Int var offsetRight: Int var offsetBottom: Int From 9e13df487ad052a57c89ce9a4d383a89e5ddab8f Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 16:52:57 +0800 Subject: [PATCH 10/16] Fix slow operations are prohibited on EDT Fix: #4605 --- src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt index 53da5fd30..4c134a861 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt @@ -18,6 +18,7 @@ import com.intellij.util.messages.Topic import com.intellij.util.xmlb.XmlSerializerUtil import com.intellij.util.xmlb.annotations.Tag import com.intellij.util.xmlb.annotations.Transient +import org.jetbrains.concurrency.runAsync import kotlin.properties.Delegates /** @@ -175,8 +176,10 @@ class Settings : PersistentStateComponent { LOG.d("===== Settings Data Version: $dataVersion =====") if (dataVersion < CURRENT_DATA_VERSION) { - migrate() - properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0) + runAsync { + migrate() + properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0) + } } } From e3fbd5797ad76e004b06efde2e71cbf4974514db Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 17:53:36 +0800 Subject: [PATCH 11/16] Fix parent disposable has already been disposed Fix: #4595 --- .../plugin/translate/ui/TranslationWidget.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 17d9ba024..18136d031 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt @@ -41,6 +41,8 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico private var isLoadingTranslationEngines = false + private var isDisposed = false + init { setTextAlignment(CENTER_ALIGNMENT) } @@ -102,7 +104,11 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico } private fun showGotItTooltipIfNeed() { - val id = "${TranslationPlugin.PLUGIN_ID}.tooltip.new.translation.engines.openai" + if (isDisposed) { + return + } + + val id = "${TranslationPlugin.PLUGIN_ID}.tooltip.new.translation.engines.openai000" val message = message("got.it.tooltip.text.new.translation.engines") GotItTooltip(id, message, this) .withHeader(message("got.it.tooltip.title.new.translation.engines")) @@ -130,6 +136,8 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico .disposeAfterProcessing(widgetRef) } - override fun dispose() {} + override fun dispose() { + isDisposed = true + } } \ No newline at end of file From 7a794f850fe253f5d066f21c922e4c3f2d446266 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 17:54:35 +0800 Subject: [PATCH 12/16] Fix "GotIt" tooltip key --- .../cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 18136d031..1aff9e3f9 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt @@ -108,7 +108,7 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico return } - val id = "${TranslationPlugin.PLUGIN_ID}.tooltip.new.translation.engines.openai000" + val id = "${TranslationPlugin.PLUGIN_ID}.tooltip.new.translation.engines.openai" val message = message("got.it.tooltip.text.new.translation.engines") GotItTooltip(id, message, this) .withHeader(message("got.it.tooltip.title.new.translation.engines")) From 971253e81d93879a3f2f5710a558765b6a76daf2 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 18:34:41 +0800 Subject: [PATCH 13/16] Catch canceled exception when canceling translation engine popup Fix: #4610 --- .../cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt | 4 ++++ 1 file changed, 4 insertions(+) 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 1aff9e3f9..060d59084 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt @@ -17,6 +17,7 @@ import cn.yiiguxing.plugin.translate.util.concurrent.successOnUiThread import cn.yiiguxing.plugin.translate.util.invokeLaterIfNeeded import com.intellij.ide.DataManager import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.DumbService import com.intellij.openapi.project.Project import com.intellij.openapi.wm.IconLikeCustomStatusBarWidget @@ -130,6 +131,9 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico val at = Point(0, -popup.content.preferredSize.height) popup.show(RelativePoint(widget, at)) } + .onError { + logger().warn("Failed to show translation engines popup.", it) + } .finishOnUiThread(widgetRef, ModalityState.any()) { widget, _ -> widget.isLoadingTranslationEngines = false } From b7bd043e512b32023f56573b3f15350efee75ad4 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 18:59:12 +0800 Subject: [PATCH 14/16] Fix write-unsafe context Fix: #4749 --- .../translate/trans/TranslateService.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 ae572351c..8968e307c 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/TranslateService.kt @@ -34,7 +34,7 @@ class TranslateService private constructor() : Disposable { var translator: Translator = DEFAULT_TRANSLATOR private set - private val listeners = mutableMapOf>() + private val listeners = mutableMapOf>() init { setTranslator(Settings.instance.translator) @@ -78,11 +78,12 @@ class TranslateService private constructor() : Disposable { } val key = ListenerKey(text, srcLang, targetLang) + val listenerInfo = ListenerInfo(modalityState, listener) listeners[key]?.let { - it += listener + it += listenerInfo return } - listeners[key] = mutableSetOf(listener) + listeners[key] = mutableSetOf(listenerInfo) executeOnPooledThread { try { @@ -90,7 +91,7 @@ class TranslateService private constructor() : Disposable { translate(text, srcLang, targetLang).let { translation -> translation.favoriteId = getFavoriteId(translation) CacheService.putMemoryCache(text, srcLang, targetLang, id, translation) - invokeLater(modalityState) { listeners.run(key) { onSuccess(translation) } } + listeners.run(key) { onSuccess(translation) } } } } catch (error: Throwable) { @@ -101,7 +102,7 @@ class TranslateService private constructor() : Disposable { // 将异常写入IDE异常池,以便用户反馈 investigate(text, srcLang, targetLang, error) } - invokeLater(modalityState) { listeners.run(key) { onError(error) } } + listeners.run(key) { onError(error) } } } } @@ -123,11 +124,13 @@ class TranslateService private constructor() : Disposable { LOG.error("Translation error[${translator.id}]: ${error.message}", error, requestAttachment) } - private inline fun MutableMap>.run( + private inline fun MutableMap>.run( key: ListenerKey, - action: TranslateListener.() -> Unit + crossinline action: TranslateListener.() -> Unit ) { - remove(key)?.forEach { it.action() } + remove(key)?.forEach { info -> + invokeLater(info.modalityState) { info.listener.action() } + } } private fun Translation.updateFavoriteStateIfNeed(favorites: List) { @@ -189,6 +192,8 @@ class TranslateService private constructor() : Disposable { private data class ListenerKey(val text: String, val srcLang: Lang, val targetLang: Lang) + 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 From c0beaea54025e947057d925566783660bf0ed39b Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 20:05:02 +0800 Subject: [PATCH 15/16] Update changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50adba065..390b69a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +- Fix the problem of missing required parameters for document translation in the Youdao translation engine. +- Other known bug fixes. +- 修复有道翻译引擎文档翻译缺少必需参数的问题 +- 其他已知问题修复 + ## [3.5.5] (2023/10/15) - Added support for RustRover and the new Rust plugin. From 2020dd8532eb45c734a19453adc1dc9a0e53d314 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 19 Nov 2023 20:05:32 +0800 Subject: [PATCH 16/16] :triangular_flag_on_post: v3.5.6 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3408df5f4..1c12cdc10 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.5.5 +pluginMajorVersion = 3.5.6 pluginPreReleaseVersion = pluginBuildMetadata = autoSnapshotVersion = true