diff --git a/CHANGELOG.md b/CHANGELOG.md index 275f7aee4..3dacfe683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Translation Plugin Changelog ## [Unreleased] +- Fixed the problem that the translation engine could not be switched when installing the plugin for the first time. +- Fixed the problem that Alibaba Translate could not parse translations in some cases. +- 修复了首次安装插件时无法切换翻译引擎的问题 +- 修复了阿里翻译在某些情况下无法解析翻译的问题 ## [3.5.2] (2023/08/16) - Bug fixes. diff --git a/gradle.properties b/gradle.properties index 3542cd1a3..6c9e9181d 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.2 +pluginMajorVersion = 3.5.3 pluginPreReleaseVersion = pluginBuildMetadata = autoSnapshotVersion = true @@ -32,7 +32,7 @@ platformPlugins = java, org.jetbrains.kotlin, \ kotlin.stdlib.default.dependency = false # Gradle Releases -> https://github.com/gradle/gradle/releases -gradleVersion = 8.2.1 +gradleVersion = 8.3 # Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html org.gradle.configuration-cache = true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5c56c802f..8cfb0d054 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,10 +7,10 @@ ideaCompat = "0.0.2" junit = "4.13.2" # plugins -kotlin = "1.9.0" +kotlin = "1.9.10" kover = "0.7.3" qodana = "0.1.13" -changelog = "2.1.2" +changelog = "2.2.0" gradleIntelliJPlugin = "1.15.0" [libraries] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c747538fb..d11cdd907 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt index 002a99051..1006f3f43 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt @@ -167,22 +167,22 @@ class Settings : PersistentStateComponent { override fun getState(): Settings = this override fun loadState(state: Settings) { - try { - XmlSerializerUtil.copyBean(state, this) + XmlSerializerUtil.copyBean(state, this) - val properties: PropertiesComponent = PropertiesComponent.getInstance() - val dataVersion = properties.getInt(DATA_VERSION_KEY, 0) + val properties: PropertiesComponent = PropertiesComponent.getInstance() + val dataVersion = properties.getInt(DATA_VERSION_KEY, 0) - LOG.d("===== Settings Data Version: $dataVersion =====") - if (dataVersion < CURRENT_DATA_VERSION) { - migrate() - properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0) - } - } finally { - isInitialized = true + LOG.d("===== Settings Data Version: $dataVersion =====") + if (dataVersion < CURRENT_DATA_VERSION) { + migrate() + properties.setValue(DATA_VERSION_KEY, CURRENT_DATA_VERSION, 0) } } + override fun initializeComponent() { + isInitialized = true + } + companion object { /** diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslation.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslation.kt index a858e25a1..8c2a1f86b 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslation.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/ali/AliTranslation.kt @@ -25,9 +25,9 @@ data class AliTranslation( override fun toTranslation(): Translation { check(isSuccessful) { "Cannot convert to Translation: errorCode=${code}" } - check(data.translation.isNotEmpty()) { "Cannot convert to Translation: data.translation = null" } - return Translation(query, data.translation, src, target, listOf(src)) + val translation = data.translation.takeIf { it.isNotEmpty() } ?: query + return Translation(query, translation, src, target, listOf(src)) } } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslatorService.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslatorService.kt index 37140e23a..0e7c7eb1c 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslatorService.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftTranslatorService.kt @@ -58,7 +58,10 @@ internal class MicrosoftTranslatorService { val promise = asyncLatch { latch -> runAsync { latch.await(100, TimeUnit.MILLISECONDS) - Http.get(AUTH_URL) { userAgent() } + Http.get(AUTH_URL) { + accept("*/*") + userAgent() + } } .onError { LOG.w("Failed to get access token", it) } .onSuccess(::updateAccessToken) 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 5327bab8f..3bd2016e1 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/update/UpdateManager.kt @@ -122,6 +122,7 @@ class UpdateManager : BaseStartupActivity() { .createNotification(content, NotificationType.INFORMATION) .setTitle(title) .setImportant(true) + .setIcon(TranslationIcons.Logo) .apply { setListener(Notifications.UrlOpeningListener(false)) } diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Http.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Http.kt index b9b564a3f..57d385eff 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Http.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Http.kt @@ -165,8 +165,8 @@ object Http { } private fun getUserAgent(): String { - val chrome = "Chrome/112.0.0.0" - val edge = "Edg/112.0.1722.39" + val chrome = "Chrome/115.0.0.0" + val edge = "Edg/115.0.1901.203" val safari = "Safari/537.36" val systemInfo = "Windows NT ${SystemInfoRt.OS_VERSION}; Win64; x64" @Suppress("SpellCheckingInspection") diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Notifications.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Notifications.kt index c61f284dc..c02bc1498 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Notifications.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/util/Notifications.kt @@ -9,6 +9,8 @@ import com.intellij.notification.* import com.intellij.notification.impl.NotificationFullContent import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.project.Project +import icons.TranslationIcons +import javax.swing.Icon import javax.swing.event.HyperlinkEvent @@ -21,6 +23,11 @@ object Notifications { private val DEFAULT_NOTIFICATION_CUSTOMIZER: (Notification) -> Unit = { } + private fun getNotificationIcon(type: NotificationType): Icon? = when (type) { + NotificationType.INFORMATION -> TranslationIcons.Logo + else -> null + } + fun showNotification( title: String, message: String, @@ -32,6 +39,7 @@ object Notifications { NotificationGroupManager.getInstance() .getNotificationGroup(groupId) .createNotification(message, type) + .setIcon(getNotificationIcon(type)) .setTitle(title) .apply { notificationCustomizer(this) } .show(project) @@ -47,6 +55,7 @@ object Notifications { ) { val group = NotificationGroupManager.getInstance().getNotificationGroup(groupId) val notification = FullContentNotification(group.displayId, title, message, type) + notification.setIcon(getNotificationIcon(type)) notificationCustomizer(notification) notification.show(project) } diff --git a/src/main/kotlin/icons/TranslationIcons.kt b/src/main/kotlin/icons/TranslationIcons.kt index 35c5b130f..0fb28b83a 100644 --- a/src/main/kotlin/icons/TranslationIcons.kt +++ b/src/main/kotlin/icons/TranslationIcons.kt @@ -7,6 +7,9 @@ import javax.swing.Icon object TranslationIcons { + @JvmField + val Logo: Icon = load("/icons/logo.svg") + @JvmField val Translation: Icon = load("/icons/translation.svg") diff --git a/src/main/resources/icons/logo.svg b/src/main/resources/icons/logo.svg new file mode 100644 index 000000000..caaef7633 --- /dev/null +++ b/src/main/resources/icons/logo.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file