From 40bdc099e344588f59c8f3ef559d2c924dbf03f4 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 19 Feb 2020 21:54:57 +0900 Subject: [PATCH] i18n: Add bundle for idea-gradle-native --- .../konan/KotlinGradleNativeBundle.properties | 18 +++++ .../ide/konan/KotlinGradleNativeBundle.kt | 25 +++++++ .../KotlinNativeABICompatibilityChecker.kt | 69 +++++++------------ ...KotlinNativeABICompatibilityChecker.kt.192 | 69 +++++++------------ ...nGradleNativeMultiplatformModuleBuilder.kt | 5 +- .../gradle/KotlinNativeGradleConfigurator.kt | 3 +- 6 files changed, 100 insertions(+), 89 deletions(-) create mode 100644 idea/idea-gradle-native/resources/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.properties create mode 100644 idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.kt diff --git a/idea/idea-gradle-native/resources/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.properties b/idea/idea-gradle-native/resources/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.properties new file mode 100644 index 00000000000..1d6d6545da5 --- /dev/null +++ b/idea/idea-gradle-native/resources/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.properties @@ -0,0 +1,18 @@ +native.gradle.name=Native | Gradle +native.gradle.name.short=Native +native.gradle.description=Gradle-based Kotlin project for native binaries + +error.incompatible.libraries.title=Incompatible Kotlin/Native libraries + +error.incompatible.libraries=There {0,choice,1#is a library|2#are {0} libraries} libraries from the Kotlin/Native {1} distribution attached to the project: {2} +error.incompatible.libraries.newer=These libraries were compiled with a newer Kotlin/Native compiler and can't be read in IDE. +error.incompatible.libraries.older=These libraries were compiled with an older Kotlin/Native compiler and can't be read in IDE. +error.incompatible.libraries.recipe=Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version {0}. Then re-import the project in IDE. + +error.incompatible.3p.libraries.newer=There {0,choice,1#is a third-party library|2#are {0} third-party libraries} attached to the project that {0,choice,1#was|2#were} compiled with a newer Kotlin/Native compiler and can't be read in IDE: +error.incompatible.3p.libraries.older=There {0,choice,1#is a third-party library|2#are {0} third-party libraries} attached to the project that {0,choice,1#was|2#were} compiled with an older Kotlin/Native compiler and can't be read in IDE: +error.incompatible.3p.libraries.recipe=Please edit Gradle buildfile(s) and specify library a version compatible with Kotlin/Native {0}. Then re-import the project in IDE. + +error.incompatible.user.libraries.newer=There {0,choice,1#is a library|2#are {0} third-party libraries} attached to the project that {0,choice,1#was|2#were} compiled with a newer Kotlin/Native compiler and can't be read in IDE: +error.incompatible.user.libraries.older=There {0,choice,1#is a library|2#are {0} third-party libraries} attached to the project that {0,choice,1#was|2#were} compiled with an older Kotlin/Native compiler and can't be read in IDE: +error.incompatible.user.libraries.recipe=Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version {0}. Then rebuild the project and re-import it in IDE. \ No newline at end of file diff --git a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.kt b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.kt new file mode 100644 index 00000000000..8135a9502a6 --- /dev/null +++ b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinGradleNativeBundle.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.ide.konan + +import com.intellij.CommonBundle +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey +import org.jetbrains.kotlin.idea.core.util.KotlinBundleBase +import org.jetbrains.kotlin.idea.debugger.evaluate.KotlinDebuggerEvaluationBundle +import java.util.* + +object KotlinGradleNativeBundle : KotlinBundleBase() { + @NonNls + private const val BUNDLE = "org.jetbrains.kotlin.ide.konan.KotlinGradleNativeBundle" + + override fun createBundle(): ResourceBundle = ResourceBundle.getBundle(BUNDLE) + + @JvmStatic + fun message(@NonNls @PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any?): String { + return CommonBundle.message(KotlinDebuggerEvaluationBundle.bundle, key, *params) + } +} \ No newline at end of file diff --git a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt index d2cc4539761..cd4782c289d 100644 --- a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt +++ b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt @@ -124,37 +124,30 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec val libraries = librariesByGroups.getValue(key).sortedWith(compareBy(LIBRARY_NAME_COMPARATOR) { (libraryName, _) -> libraryName }) - val compilerVersionText = if (isOldMetadata) "an older" else "a newer" val message = when (libraryGroup) { is LibraryGroup.FromDistribution -> { - val libraryNamesInOneLine = - libraries.joinToString(limit = MAX_LIBRARY_NAMES_IN_ONE_LINE) { (libraryName, _) -> libraryName } - - """ - |There are ${libraries.size} libraries from the Kotlin/Native ${libraryGroup.kotlinVersion} distribution attached to the project: $libraryNamesInOneLine - | - |These libraries were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE. Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() + val libraryNamesInOneLine = libraries + .joinToString(limit = MAX_LIBRARY_NAMES_IN_ONE_LINE) { (libraryName, _) -> libraryName } + val text = KotlinGradleNativeBundle.message( + "error.incompatible.libraries", + libraries.size, libraryGroup.kotlinVersion, libraryNamesInOneLine + ) + val explanation = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.libraries.older") + false -> KotlinGradleNativeBundle.message("error.incompatible.libraries.newer") + } + val recipe = KotlinGradleNativeBundle.message("error.incompatible.libraries.recipe", bundledRuntimeVersion()) + "$text\n\n$explanation\n$recipe" } is LibraryGroup.ThirdParty -> { - if (libraries.size == 1) { - """ - |There is a third-party library attached to the project that was compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: ${libraries.single() - .first} - | - |Please edit Gradle buildfile(s) and specify library version compatible with Kotlin/Native ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() - } else { - val librariesLineByLine = libraries.joinToString(separator = "\n") { (libraryName, _) -> libraryName } - - """ - |There are ${libraries.size} third-party libraries attached to the project that were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |$librariesLineByLine - | - |Please edit Gradle buildfile(s) and specify library versions compatible with Kotlin/Native ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() + val text = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.older", libraries.size) + false -> KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.newer", libraries.size) } + val librariesLineByLine = libraries.joinToString(separator = "\n") { (libraryName, _) -> libraryName } + val recipe = KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.recipe", bundledRuntimeVersion()) + "$text\n$librariesLineByLine\n\n$recipe" } is LibraryGroup.User -> { val projectRoot = project.guessProjectDir()?.canonicalPath @@ -172,23 +165,13 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec return "\"$libraryName\" at $relativeRoot" } - if (libraries.size == 1) { - """ - |There is a library attached to the project that was compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |${getLibraryTextToPrint(libraries.single())} - | - |Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then rebuild the project and re-import it in IDE. - """.trimMargin() - } else { - val librariesLineByLine = libraries.joinToString(separator = "\n", transform = ::getLibraryTextToPrint) - - """ - |There are ${libraries.size} libraries attached to the project that were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |$librariesLineByLine - | - |Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then rebuild the project and re-import it in IDE. - """.trimMargin() + val text = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.user.libraries.older", libraries.size) + false -> KotlinGradleNativeBundle.message("error.incompatible.user.libraries.newer", libraries.size) } + val librariesLineByLine = libraries.joinToString(separator = "\n", transform = ::getLibraryTextToPrint) + val recipe = KotlinGradleNativeBundle.message("error.incompatible.user.libraries.recipe", bundledRuntimeVersion()) + "$text\n$librariesLineByLine\n\n$recipe" } } @@ -236,7 +219,7 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec private const val MAX_LIBRARY_NAMES_IN_ONE_LINE = 5 - private const val NOTIFICATION_TITLE = "Incompatible Kotlin/Native libraries" - private const val NOTIFICATION_GROUP_ID = NOTIFICATION_TITLE + private val NOTIFICATION_TITLE = KotlinGradleNativeBundle.message("error.incompatible.libraries.title") + private val NOTIFICATION_GROUP_ID = NOTIFICATION_TITLE } } diff --git a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt.192 b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt.192 index 0b598327518..e7096194b1d 100644 --- a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt.192 +++ b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/KotlinNativeABICompatibilityChecker.kt.192 @@ -125,37 +125,30 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec val libraries = librariesByGroups.getValue(key).sortedWith(compareBy(LIBRARY_NAME_COMPARATOR) { (libraryName, _) -> libraryName }) - val compilerVersionText = if (isOldMetadata) "an older" else "a newer" val message = when (libraryGroup) { is LibraryGroup.FromDistribution -> { - val libraryNamesInOneLine = - libraries.joinToString(limit = MAX_LIBRARY_NAMES_IN_ONE_LINE) { (libraryName, _) -> libraryName } - - """ - |There are ${libraries.size} libraries from the Kotlin/Native ${libraryGroup.kotlinVersion} distribution attached to the project: $libraryNamesInOneLine - | - |These libraries were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE. Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() + val libraryNamesInOneLine = libraries + .joinToString(limit = MAX_LIBRARY_NAMES_IN_ONE_LINE) { (libraryName, _) -> libraryName } + val text = KotlinGradleNativeBundle.message( + "error.incompatible.libraries", + libraries.size, libraryGroup.kotlinVersion, libraryNamesInOneLine + ) + val explanation = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.libraries.older") + false -> KotlinGradleNativeBundle.message("error.incompatible.libraries.newer") + } + val recipe = KotlinGradleNativeBundle.message("error.incompatible.libraries.recipe", bundledRuntimeVersion()) + "$text\n\n$explanation\n$recipe" } is LibraryGroup.ThirdParty -> { - if (libraries.size == 1) { - """ - |There is a third-party library attached to the project that was compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: ${libraries.single() - .first} - | - |Please edit Gradle buildfile(s) and specify library version compatible with Kotlin/Native ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() - } else { - val librariesLineByLine = libraries.joinToString(separator = "\n") { (libraryName, _) -> libraryName } - - """ - |There are ${libraries.size} third-party libraries attached to the project that were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |$librariesLineByLine - | - |Please edit Gradle buildfile(s) and specify library versions compatible with Kotlin/Native ${bundledRuntimeVersion()}. Then re-import the project in IDE. - """.trimMargin() + val text = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.older", libraries.size) + false -> KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.newer", libraries.size) } + val librariesLineByLine = libraries.joinToString(separator = "\n") { (libraryName, _) -> libraryName } + val recipe = KotlinGradleNativeBundle.message("error.incompatible.3p.libraries.recipe", bundledRuntimeVersion()) + "$text\n$librariesLineByLine\n\n$recipe" } is LibraryGroup.User -> { val projectRoot = project.guessProjectDir()?.canonicalPath @@ -173,23 +166,13 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec return "\"$libraryName\" at $relativeRoot" } - if (libraries.size == 1) { - """ - |There is a library attached to the project that was compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |${getLibraryTextToPrint(libraries.single())} - | - |Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then rebuild the project and re-import it in IDE. - """.trimMargin() - } else { - val librariesLineByLine = libraries.joinToString(separator = "\n", transform = ::getLibraryTextToPrint) - - """ - |There are ${libraries.size} libraries attached to the project that were compiled with $compilerVersionText Kotlin/Native compiler and can't be read in IDE: - |$librariesLineByLine - | - |Please edit Gradle buildfile(s) to use Kotlin Gradle plugin version ${bundledRuntimeVersion()}. Then rebuild the project and re-import it in IDE. - """.trimMargin() + val text = when (isOldMetadata) { + true -> KotlinGradleNativeBundle.message("error.incompatible.user.libraries.older", libraries.size) + false -> KotlinGradleNativeBundle.message("error.incompatible.user.libraries.newer", libraries.size) } + val librariesLineByLine = libraries.joinToString(separator = "\n", transform = ::getLibraryTextToPrint) + val recipe = KotlinGradleNativeBundle.message("error.incompatible.user.libraries.recipe", bundledRuntimeVersion()) + "$text\n$librariesLineByLine\n\n$recipe" } } @@ -237,7 +220,7 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec private const val MAX_LIBRARY_NAMES_IN_ONE_LINE = 5 - private const val NOTIFICATION_TITLE = "Incompatible Kotlin/Native libraries" - private const val NOTIFICATION_GROUP_ID = NOTIFICATION_TITLE + private val NOTIFICATION_TITLE = KotlinGradleNativeBundle.message("error.incompatible.libraries.title") + private val NOTIFICATION_GROUP_ID = NOTIFICATION_TITLE } } diff --git a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinGradleNativeMultiplatformModuleBuilder.kt b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinGradleNativeMultiplatformModuleBuilder.kt index 285c0a3b978..ce81dfe7a65 100644 --- a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinGradleNativeMultiplatformModuleBuilder.kt +++ b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinGradleNativeMultiplatformModuleBuilder.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.ide.konan.gradle import com.intellij.openapi.vfs.VirtualFile +import org.jetbrains.kotlin.ide.konan.KotlinGradleNativeBundle import org.jetbrains.kotlin.idea.KotlinIcons import org.jetbrains.kotlin.idea.configuration.KotlinGradleAbstractMultiplatformModuleBuilder import org.jetbrains.kotlin.konan.target.presetName @@ -26,9 +27,9 @@ class KotlinGradleNativeMultiplatformModuleBuilder : KotlinGradleAbstractMultipl override fun getBuilderId() = "kotlin.gradle.multiplatform.native" - override fun getPresentableName() = "Native | Gradle" + override fun getPresentableName() = KotlinGradleNativeBundle.message("native.gradle.name") - override fun getDescription() = "Gradle-based Kotlin project for native binaries" + override fun getDescription() = KotlinGradleNativeBundle.message("native.gradle.description") override val notImportedCommonSourceSets = true diff --git a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinNativeGradleConfigurator.kt b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinNativeGradleConfigurator.kt index 7520798307f..21d9c68684e 100644 --- a/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinNativeGradleConfigurator.kt +++ b/idea/idea-gradle-native/src/org/jetbrains/kotlin/ide/konan/gradle/KotlinNativeGradleConfigurator.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.ide.konan.gradle +import org.jetbrains.kotlin.ide.konan.KotlinGradleNativeBundle import org.jetbrains.kotlin.ide.konan.hasKotlinNativeRuntimeInScope import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator @@ -37,6 +38,6 @@ open class KotlinNativeGradleConfigurator : KotlinWithGradleConfigurator() { companion object { const val NAME = "KotlinNative" - const val PRESENTABLE_TEXT = "Native" + val PRESENTABLE_TEXT = KotlinGradleNativeBundle.message("native.gradle.name.short") } } \ No newline at end of file