From 6ad1a9224c8007ca25a69564ddc72788f4cec9a7 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 21 Feb 2020 12:51:32 +0700 Subject: [PATCH] i18n: add bundle for idea/formatter --- .../messages/KotlinFormatterBundle.properties | 34 +++++++++ .../idea/formatter/ImportSettingsPanel.kt | 21 +++--- .../idea/formatter/KotlinFormatterBundle.kt | 18 +++++ ...KotlinLanguageCodeStyleSettingsProvider.kt | 71 +++++++++++-------- .../idea/formatter/KotlinSaveStylePanel.kt | 4 +- 5 files changed, 107 insertions(+), 41 deletions(-) create mode 100644 idea/resources/messages/KotlinFormatterBundle.properties create mode 100644 idea/src/org/jetbrains/kotlin/idea/formatter/KotlinFormatterBundle.kt diff --git a/idea/resources/messages/KotlinFormatterBundle.properties b/idea/resources/messages/KotlinFormatterBundle.properties new file mode 100644 index 00000000000..435163ba5da --- /dev/null +++ b/idea/resources/messages/KotlinFormatterBundle.properties @@ -0,0 +1,34 @@ +button.text.use.import.with.when.at.least=Use import with ''*'' when at least +button.text.use.import.with=Use import with ''*'' +button.text.use.single.name.import=Use single name import +checkbox.text.insert.imports.for.nested.classes=Insert imports for nested classes +text.names.used=\ names used +text.use.defaults.from=Use defaults from: +title.after.colon.before.declaration.type=After colon, before declaration type +title.after.colon.in.new.type.definition=After colon in new type definition +title.align.when.branches.in.columns=Align ''when'' branches in columns +title.around.arrow.in.function.types=Around arrow in function types +title.around.arrow.in=Around arrow in "when" clause +title.around.when.branches.with=Around ''when'' branches with {} +title.before.colon.after.declaration.name=Before colon, after declaration name +title.before.colon.in.new.type.definition=Before colon in new type definition +title.before.lambda.arrow=Before lambda arrow +title.chained.function.calls=Chained function calls +title.elvis.expressions=Elvis expressions +title.expression.body.functions=Expression body functions +title.function.annotations=Function annotations +title.function.call.arguments=Function call arguments +title.function.declaration.parameters=Function declaration parameters +title.function.parentheses=Function parentheses +title.in.simple.one.line.methods=In simple one line methods +title.java.statics.and.enum.members=Java Statics and Enum Members +title.load.save=Load/Save +title.other=Other +title.property.annotations=Property annotations +title.put.left.brace.on.new.line=Put left brace on new line +title.range.operator=Range operator (..) +title.top.level.symbols=Top-level Symbols +title.use.continuation.indent.in.conditions=Use continuation indent in conditions +title.use.continuation.indent=Use continuation indent +title.when.parentheses=''when'' parentheses +title.when.statements=''when'' statements \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt index 62b329db9ca..c892f00b565 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt @@ -49,7 +49,7 @@ class ImportSettingsPanelWrapper(settings: CodeStyleSettings) : CodeStyleAbstrac } class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPanel() { - private val cbImportNestedClasses = JCheckBox("Insert imports for nested classes") + private val cbImportNestedClasses = JCheckBox(KotlinFormatterBundle.message("checkbox.text.insert.imports.for.nested.classes")) private val starImportPackageEntryTable = PackageEntryTable() private val dummyImportLayoutPanel = object : ImportLayoutPanel() { @@ -59,11 +59,12 @@ class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPane private val starImportPackageTable = ImportLayoutPanel.createTableForPackageEntries(starImportPackageEntryTable, dummyImportLayoutPanel) private val nameCountToUseStarImportSelector = NameCountToUseStarImportSelector( - "Top-level Symbols", KotlinCodeStyleSettings.defaultSettings().NAME_COUNT_TO_USE_STAR_IMPORT + KotlinFormatterBundle.message("title.top.level.symbols"), KotlinCodeStyleSettings.defaultSettings().NAME_COUNT_TO_USE_STAR_IMPORT ) private val nameCountToUseStarImportForMembersSelector = NameCountToUseStarImportSelector( - "Java Statics and Enum Members", KotlinCodeStyleSettings.defaultSettings().NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS + KotlinFormatterBundle.message("title.java.statics.and.enum.members"), + KotlinCodeStyleSettings.defaultSettings().NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS ) init { @@ -80,7 +81,9 @@ class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPane add(nameCountToUseStarImportForMembersSelector.createPanel(), constraints.apply { gridy++ }) - add(OptionGroup("Other").apply { add(cbImportNestedClasses) }.createPanel(), constraints.apply { gridy++ }) + add( + OptionGroup(KotlinFormatterBundle.message("title.other")).apply { add(cbImportNestedClasses) }.createPanel(), + constraints.apply { gridy++ }) add(PackagePanel.createPackagesPanel(starImportPackageTable, starImportPackageEntryTable), constraints.apply { gridy++ @@ -155,9 +158,9 @@ class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPane } private class NameCountToUseStarImportSelector(title: String, default: Int) : OptionGroup(title) { - private val rbUseSingleImports = JRadioButton("Use single name import") - private val rbUseStarImports = JRadioButton("Use import with '*'") - private val rbUseStarImportsIfAtLeast = JRadioButton("Use import with '*' when at least ") + private val rbUseSingleImports = JRadioButton(KotlinFormatterBundle.message("button.text.use.single.name.import")) + private val rbUseStarImports = JRadioButton(KotlinFormatterBundle.message("button.text.use.import.with")) + private val rbUseStarImportsIfAtLeast = JRadioButton(KotlinFormatterBundle.message("button.text.use.import.with.when.at.least")) private val starImportLimitModel = SpinnerNumberModel(default, 2, 100, 1) private val starImportLimitField = JSpinner(starImportLimitModel) @@ -175,7 +178,9 @@ class ImportSettingsPanel(private val commonSettings: CodeStyleSettings) : JPane val constraints = GridBagConstraints().apply { gridx = GridBagConstraints.RELATIVE } this.add(rbUseStarImportsIfAtLeast, constraints) this.add(starImportLimitField, constraints) - this.add(JLabel(" names used"), constraints.apply { fill = GridBagConstraints.HORIZONTAL; weightx = 1.0 }) + this.add( + JLabel(KotlinFormatterBundle.message("text.names.used")), + constraints.apply { fill = GridBagConstraints.HORIZONTAL; weightx = 1.0 }) }, true) fun updateEnabled() { diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinFormatterBundle.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinFormatterBundle.kt new file mode 100644 index 00000000000..4c22fc75e97 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinFormatterBundle.kt @@ -0,0 +1,18 @@ +/* + * 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.idea.formatter + +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey +import org.jetbrains.kotlin.util.AbstractKotlinBundle + +@NonNls +private const val BUNDLE = "messages.KotlinFormatterBundle" + +object KotlinFormatterBundle : AbstractKotlinBundle(BUNDLE) { + @JvmStatic + fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String = getMessage(key, *params) +} diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index c762b44f710..3d49d24d926 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -194,61 +194,61 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide showCustomOption( KotlinCodeStyleSettings::SPACE_AROUND_RANGE, - "Range operator (..)", + KotlinFormatterBundle.message("title.range.operator"), CodeStyleSettingsCustomizable.SPACES_AROUND_OPERATORS ) showCustomOption( KotlinCodeStyleSettings::SPACE_BEFORE_TYPE_COLON, - "Before colon, after declaration name", + KotlinFormatterBundle.message("title.before.colon.after.declaration.name"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_AFTER_TYPE_COLON, - "After colon, before declaration type", + KotlinFormatterBundle.message("title.after.colon.before.declaration.type"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_BEFORE_EXTEND_COLON, - "Before colon in new type definition", + KotlinFormatterBundle.message("title.before.colon.in.new.type.definition"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_AFTER_EXTEND_COLON, - "After colon in new type definition", + KotlinFormatterBundle.message("title.after.colon.in.new.type.definition"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD, - "In simple one line methods", + KotlinFormatterBundle.message("title.in.simple.one.line.methods"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_AROUND_FUNCTION_TYPE_ARROW, - "Around arrow in function types", + KotlinFormatterBundle.message("title.around.arrow.in.function.types"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_AROUND_WHEN_ARROW, - "Around arrow in \"when\" clause", + KotlinFormatterBundle.message("title.around.arrow.in"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_BEFORE_LAMBDA_ARROW, - "Before lambda arrow", + KotlinFormatterBundle.message("title.before.lambda.arrow"), CodeStyleSettingsCustomizable.SPACES_OTHER ) showCustomOption( KotlinCodeStyleSettings::SPACE_BEFORE_WHEN_PARENTHESES, - "'when' parentheses", + KotlinFormatterBundle.message("title.when.parentheses"), CodeStyleSettingsCustomizable.SPACES_BEFORE_PARENTHESES ) } @@ -285,52 +285,61 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide "WRAP_FIRST_METHOD_IN_CALL_CHAIN", "ASSIGNMENT_WRAP" ) - consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, "'when' statements") - consumer.renameStandardOption("FIELD_ANNOTATION_WRAP", "Property annotations") - consumer.renameStandardOption("METHOD_PARAMETERS_WRAP", "Function declaration parameters") - consumer.renameStandardOption("CALL_PARAMETERS_WRAP", "Function call arguments") - consumer.renameStandardOption("METHOD_CALL_CHAIN_WRAP", "Chained function calls") - consumer.renameStandardOption("METHOD_ANNOTATION_WRAP", "Function annotations") - consumer.renameStandardOption(CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARENTHESES, "Function parentheses") + consumer.renameStandardOption( + CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, + KotlinFormatterBundle.message("title.when.statements") + ) + consumer.renameStandardOption("FIELD_ANNOTATION_WRAP", KotlinFormatterBundle.message("title.property.annotations")) + consumer.renameStandardOption( + "METHOD_PARAMETERS_WRAP", + KotlinFormatterBundle.message("title.function.declaration.parameters") + ) + consumer.renameStandardOption("CALL_PARAMETERS_WRAP", KotlinFormatterBundle.message("title.function.call.arguments")) + consumer.renameStandardOption("METHOD_CALL_CHAIN_WRAP", KotlinFormatterBundle.message("title.chained.function.calls")) + consumer.renameStandardOption("METHOD_ANNOTATION_WRAP", KotlinFormatterBundle.message("title.function.annotations")) + consumer.renameStandardOption( + CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARENTHESES, + KotlinFormatterBundle.message("title.function.parentheses") + ) showCustomOption(KotlinCodeStyleSettings::ALLOW_TRAILING_COMMA, "Use trailing comma") showCustomOption( KotlinCodeStyleSettings::ALIGN_IN_COLUMNS_CASE_BRANCH, - "Align 'when' branches in columns", + KotlinFormatterBundle.message("title.align.when.branches.in.columns"), CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT ) showCustomOption( KotlinCodeStyleSettings::LBRACE_ON_NEXT_LINE, - "Put left brace on new line", + KotlinFormatterBundle.message("title.put.left.brace.on.new.line"), CodeStyleSettingsCustomizable.WRAPPING_BRACES ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_PARAMETER_LISTS, - "Use continuation indent", + KotlinFormatterBundle.message("title.use.continuation.indent"), CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARAMETERS ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ARGUMENT_LISTS, - "Use continuation indent", + KotlinFormatterBundle.message("title.use.continuation.indent"), CodeStyleSettingsCustomizable.WRAPPING_METHOD_ARGUMENTS_WRAPPING ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_CHAINED_CALLS, - "Use continuation indent", + KotlinFormatterBundle.message("title.use.continuation.indent"), CodeStyleSettingsCustomizable.WRAPPING_CALL_CHAIN ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_SUPERTYPE_LISTS, - "Use continuation indent", + KotlinFormatterBundle.message("title.use.continuation.indent"), CodeStyleSettingsCustomizable.WRAPPING_EXTENDS_LIST ) showCustomOption( KotlinCodeStyleSettings::WRAP_EXPRESSION_BODY_FUNCTIONS, - "Expression body functions", + KotlinFormatterBundle.message("title.expression.body.functions"), options = *arrayOf( CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON @@ -338,12 +347,12 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES, - "Use continuation indent", - "Expression body functions" + KotlinFormatterBundle.message("title.use.continuation.indent"), + KotlinFormatterBundle.message("title.expression.body.functions") ) showCustomOption( KotlinCodeStyleSettings::WRAP_ELVIS_EXPRESSIONS, - "Elvis expressions", + KotlinFormatterBundle.message("title.elvis.expressions"), options = *arrayOf( CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON @@ -351,8 +360,8 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ELVIS, - title = "Use continuation indent", - groupName = "Elvis expressions" + title = KotlinFormatterBundle.message("title.use.continuation.indent"), + groupName = KotlinFormatterBundle.message("title.elvis.expressions") ) @Suppress("InvalidBundleOrProperty") showCustomOption( @@ -362,7 +371,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide ) showCustomOption( KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_IF_CONDITIONS, - "Use continuation indent in conditions", + KotlinFormatterBundle.message("title.use.continuation.indent.in.conditions"), CodeStyleSettingsCustomizable.WRAPPING_IF_STATEMENT ) } @@ -375,7 +384,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide ) showCustomOption( KotlinCodeStyleSettings::BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES, - "Around 'when' branches with {}", + KotlinFormatterBundle.message("title.around.when.branches.with"), CodeStyleSettingsCustomizable.BLANK_LINES ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt index 3485b81f976..e1ce9ed1b43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt @@ -27,7 +27,7 @@ class KotlinSaveStylePanel(settings: CodeStyleSettings) : CodeStyleAbstractPanel override fun getFileType() = throw UnsupportedOperationException() override fun getPreviewText(): String? = null - override fun getTabTitle(): String = "Load/Save" + override fun getTabTitle(): String = KotlinFormatterBundle.message("title.load.save") private data class SaveItem(val label: String, val id: String?) @@ -63,7 +63,7 @@ class KotlinSaveStylePanel(settings: CodeStyleSettings) : CodeStyleAbstractPanel } }) - add(JLabel("Use defaults from:")) + add(JLabel(KotlinFormatterBundle.message("text.use.defaults.from"))) add(saveDefaultsComboBox) }) }