i18n: Move scheme import/export source/target names to a property bundle
authorRustam Vishnyakov <rustam.vishnyakov@jetbrains.com>
Wed, 12 Aug 2020 15:00:39 +0000 (18:00 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 13 Aug 2020 11:22:55 +0000 (11:22 +0000)
Covers also IDEA-247987 i18n: internationalize export options

GitOrigin-RevId: d1835fb9caad5272c6c0435ce9a94839a693503f

platform/platform-api/resources/messages/ApplicationBundle.properties
platform/platform-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java
platform/platform-impl/src/com/intellij/openapi/options/SchemeConvertorEPBase.java [new file with mode: 0644]
platform/platform-impl/src/com/intellij/openapi/options/SchemeExporterEP.java
platform/platform-impl/src/com/intellij/openapi/options/SchemeImporterEP.java
platform/platform-resources/src/META-INF/LangExtensions.xml
plugins/editorconfig/resources/META-INF/plugin.xml
plugins/editorconfig/resources/messages/EditorConfigBundle.properties

index 69c278d89af6d85e63390060bca62c15e0759813..478166cd83af690518a9b78c734c5055e8c62887 100644 (file)
@@ -765,7 +765,7 @@ checkbox.stop.3=Color #3
 checkbox.stop.4=Color #4
 checkbox.stop.5=Color #5
 checkbox.rainbow=Semantic highlighting
-rainbow.option.description=<html><font color=gray><sub>Assign each parameter or variable<br>its own color from the spectrum below:
+rainbow.option.description=<html><font color=gray><subexporter.>Assign each parameter or variable<br>its own color from the spectrum below:
 
 color.scheme.reset=Reset
 color.scheme.reset.message=Reset the scheme to its default values?\nNote: all the changes you have made to the scheme will be lost.
@@ -796,6 +796,10 @@ title.save.code.style.scheme.as=Duplicate Code Style Scheme As
 title.save.color.scheme.as=Duplicate Color Scheme As
 settings.code.style.visual.guides=Visual guides
 settings.code.style.general.visual.guides.hint=Specify one guide (80) or several (80, 120)
+settings.export.target.intellij.xml=IntelliJ IDEA code style XML
+settings.export.target.color.scheme=IntelliJ IDEA color scheme (.icls)
+settings.export.target.color.scheme.plugin=Color scheme plugin .jar
+settings.import.source.color.scheme=IntelliJ IDEA color scheme (.icls) or settings (.jar)
 
 project.code.style.migration.title=Project code style settings migration
 project.code.style.migration.message=The code style settings of your project {0} were migrated to the new format. We''re keeping the old format for now, for backwards compatibility.
index 38207175a5d05e7e1bd4b7e9f008e964fd9dfed6..e51e159705cc89d272681c0a4e2fffcf7c480f02 100644 (file)
@@ -56,7 +56,7 @@ public abstract class AbstractSchemeActions<T extends Scheme> {
   protected Collection<String> getSchemeImportersNames() {
     List<String> importersNames = new ArrayList<>();
     for (SchemeImporterEP<T> importerEP : SchemeImporterEP.getExtensions(getSchemeType())) {
-      importersNames.add(importerEP.name);
+      importersNames.add(importerEP.getLocalizedName());
     }
     return importersNames;
   }
@@ -65,7 +65,7 @@ public abstract class AbstractSchemeActions<T extends Scheme> {
   private Collection<String> getSchemeExporterNames() {
     List<String> exporterNames = new ArrayList<>();
     for (SchemeExporterEP<T> exporterEP : SchemeExporterEP.getExtensions(getSchemeType())) {
-      exporterNames.add(exporterEP.name);
+      exporterNames.add(exporterEP.getLocalizedName());
     }
     return exporterNames;
   }
diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemeConvertorEPBase.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemeConvertorEPBase.java
new file mode 100644 (file)
index 0000000..228b428
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.openapi.options;
+
+import com.intellij.AbstractBundle;
+import com.intellij.DynamicBundle;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.serviceContainer.BaseKeyedLazyInstance;
+import com.intellij.util.xmlb.annotations.Attribute;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ResourceBundle;
+
+public class SchemeConvertorEPBase<T> extends BaseKeyedLazyInstance<T> {
+  private static final Logger LOG = Logger.getInstance(SchemeExporterEP.class);
+
+  @Attribute("name")
+  @Nls(capitalization = Nls.Capitalization.Sentence)
+  public String name;
+
+  @Attribute("nameKey")
+  public String nameKey;
+
+  @Attribute("nameBundle")
+  public String nameBundle;
+
+  @Attribute("implementationClass")
+  public String implementationClass;
+
+  @Nullable
+  @Override
+  protected String getImplementationClassName() {
+    return implementationClass;
+  }
+
+  /**
+   * @return A localized exporter/importer name to be used in UI if <i>nameBundle</i> <b>and</b> <i>nameKey</i> attributes are specified.
+   * Otherwise the <i>name</i> attribute as is. Reports an error if the attributes are missing.
+   */
+  public @NotNull String getLocalizedName() {
+    if (nameBundle != null && nameKey != null) {
+      ResourceBundle resourceBundle = DynamicBundle.INSTANCE.getResourceBundle(nameBundle, getPluginDescriptor().getPluginClassLoader());
+      return AbstractBundle.message(resourceBundle, nameKey);
+    }
+    else if (name == null) {
+      LOG.error("Either a pair ('nameBundle', 'nameKey') or 'name' attribute must be specified.");
+    }
+    return name;
+  }
+}
index 36776f812bc9cc3655960c6f9a50f3c0d4b5628c..183c36f7f0ff2b91f5db5b33275748e4ea638299 100644 (file)
@@ -2,9 +2,7 @@
 package com.intellij.openapi.options;
 
 import com.intellij.openapi.extensions.ExtensionPointName;
-import com.intellij.serviceContainer.BaseKeyedLazyInstance;
 import com.intellij.util.xmlb.annotations.Attribute;
-import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -13,29 +11,22 @@ import java.util.Collection;
 import java.util.List;
 
 /**
- * Extension point for schemes exporters.
- *
- * @author Rustam Vishnyakov
+ * Extension point for schemes exporters. Example of definition in {@code plugin.xml}:
+ * <pre>
+ * &lt;schemeExporter
+ *         nameBundle="messages.PluginBundle"
+ *         nameKey="bundle.name.key"
+ *         schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme"
+ *         implementationClass="org.acme.ExporterClass"&gt;
+ * </pre>
+ * {@code ExporterClass} must extend {@link SchemeExporter}
  */
-public final class SchemeExporterEP<S extends Scheme> extends BaseKeyedLazyInstance<SchemeExporter<S>> {
+public final class SchemeExporterEP<S extends Scheme> extends SchemeConvertorEPBase<SchemeExporter<S>> {
   public static final ExtensionPointName<SchemeExporterEP<?>> EP_NAME = ExtensionPointName.create("com.intellij.schemeExporter");
 
-  @Attribute("name")
-  @Nls(capitalization = Nls.Capitalization.Sentence)
-  public String name;
-
   @Attribute("schemeClass")
   public String schemeClass;
 
-  @Attribute("implementationClass")
-  public String implementationClass;
-
-  @Nullable
-  @Override
-  protected String getImplementationClassName() {
-    return implementationClass;
-  }
-
   /**
    * Finds extensions supporting the given {@code schemeClass}
    * @param schemeClass The class of the scheme to search extensions for.
@@ -63,10 +54,11 @@ public final class SchemeExporterEP<S extends Scheme> extends BaseKeyedLazyInsta
   @Nullable
   public static <S extends Scheme> SchemeExporter<S> getExporter(@NotNull String name, Class<S> schemeClass) {
     for (SchemeExporterEP<S> exporterEP : getExtensions(schemeClass)) {
-      if (name.equals(exporterEP.name)) {
+      if (name.equals(exporterEP.getLocalizedName())) {
         return exporterEP.getInstance();
       }
     }
     return null;
   }
+
 }
index d1560c4cdcb9023d9241fc7f891e00eefff3e59a..4960ff535e7e128e9f532f27f2f9003a845774c3 100644 (file)
  */
 package com.intellij.openapi.options;
 
-import com.intellij.openapi.extensions.AbstractExtensionPointBean;
 import com.intellij.openapi.extensions.ExtensionPointName;
-import com.intellij.openapi.util.LazyInstance;
 import com.intellij.util.xmlb.annotations.Attribute;
-import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -28,32 +25,22 @@ import java.util.Collection;
 import java.util.List;
 
 /**
- * @author Rustam Vishnyakov
+ * Extension point for scheme importers. Example of definition in {@code plugin.xml}:
+ * <pre>
+ * &lt;schemeImporter
+ *         nameBundle="messages.PluginBundle"
+ *         nameKey="bundle.name.key"
+ *         schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme"
+ *         implementationClass="org.acme.ImporterClass"&gt;
+ * </pre>
+ * {@code ImporterClass} must extend {@link SchemeImporter}
  */
-public class SchemeImporterEP <S extends Scheme> extends AbstractExtensionPointBean {
+public final class SchemeImporterEP <S extends Scheme> extends SchemeConvertorEPBase<SchemeImporter<S>> {
   public static final ExtensionPointName<SchemeImporterEP> EP_NAME = ExtensionPointName.create("com.intellij.schemeImporter");
 
-  @Attribute("name")
-  @Nls(capitalization = Nls.Capitalization.Sentence)
-  public String name;
-
   @Attribute("schemeClass")
   public String schemeClass;
 
-  @Attribute("implementationClass")
-  public String implementationClass;
-
-  private final LazyInstance<SchemeImporter<S>> myImporterInstance = new LazyInstance<SchemeImporter<S>>() {
-    @Override
-    protected Class<SchemeImporter<S>> getInstanceClass() {
-      return findExtensionClass(implementationClass);
-    }
-  };
-  
-  public SchemeImporter<S> getInstance() {
-    return myImporterInstance.getValue();
-  }
-
   /**
    * Finds extensions supporting the given {@code schemeClass}
    * @param schemeClass The class of the scheme to search extensions for.
@@ -82,7 +69,7 @@ public class SchemeImporterEP <S extends Scheme> extends AbstractExtensionPointB
   @Nullable
   public static <S extends Scheme> SchemeImporter<S> getImporter(@NotNull String name, Class<S> schemeClass) {
     for (SchemeImporterEP<S> importerEP : getExtensions(schemeClass)) {
-      if (name.equals(importerEP.name)) {
+      if (name.equals(importerEP.getLocalizedName())) {
         return importerEP.getInstance();
       }
     }
index 9fa8cda44e1667616d3391e9c58c1de1631ff58d..46124dc824921b0d0e40dd89d4ea819f4b010ec1 100644 (file)
     <daemon.tooltipActionProvider order="last" id="defaultProvider" implementation="com.intellij.codeInsight.daemon.impl.DaemonTooltipActionProvider" />
 
     <schemeExporter
-        name="IntelliJ IDEA code style XML"
+        nameBundle="messages.ApplicationBundle"
+        nameKey="settings.export.target.intellij.xml"
         schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme"
         implementationClass="com.intellij.application.options.schemes.SerializableSchemeExporter"/>
     <schemeExporter
-        name="IntelliJ IDEA color scheme (.icls)"
+        nameBundle="messages.ApplicationBundle"
+        nameKey="settings.export.target.color.scheme"
         schemeClass="com.intellij.openapi.editor.colors.EditorColorsScheme"
         implementationClass="com.intellij.application.options.colors.ColorSchemeExporter"/>
     <schemeExporter
-        name="Color scheme plugin .jar"
+        nameBundle="messages.ApplicationBundle"
+        nameKey="settings.export.target.color.scheme.plugin"
         schemeClass="com.intellij.openapi.editor.colors.EditorColorsScheme"
         implementationClass="com.intellij.application.options.colors.pluginExport.ColorSchemePluginExporter"/>
     <schemeImporter
-        name="IntelliJ IDEA code style XML"
+        nameBundle="messages.ApplicationBundle"
+        nameKey="settings.export.target.intellij.xml"
         schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme"
         implementationClass="com.intellij.psi.impl.source.codeStyle.CodeStyleSchemeXmlImporter"/>
     <schemeImporter
-        name="IntelliJ IDEA color scheme (.icls) or settings (.jar)"
+        nameBundle="messages.ApplicationBundle"
+        nameKey="settings.import.source.color.scheme"
         schemeClass="com.intellij.openapi.editor.colors.EditorColorsScheme"
         implementationClass="com.intellij.application.options.colors.ColorSchemeImporter"/>
     <schemeExporter
index 01c1d2cdc5e1bbb62921c7b8dd9bc4b2c30310eb..f542639bb961bdcf268f004ca6cd6aa2a1af693c 100644 (file)
@@ -392,7 +392,8 @@ To create an EditorConfig file in a directory, right-click this directory and se
         serviceImplementation="org.editorconfig.language.services.impl.EditorConfigFileHierarchyServiceImpl"/>
 
     <schemeExporter
-        name="EditorConfig File"
+        nameKey="scheme.exporter.target.name"
+        nameBundle="messages.EditorConfigBundle"
         schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme"
         implementationClass="org.editorconfig.configmanagement.export.EditorConfigExporter"/>
     <notificationAllowlist groupIds="EditorConfig;editorconfig"/>
index 782e73f7876da7b70e176b5f26d1e0956edf5ef8..15808e79f2ba1178b54d1e9304eefbfc716a3a67 100644 (file)
@@ -232,4 +232,6 @@ dialog.message.editorconfig.already.present.in.overwrite=.editorconfig already p
 
 editor.notification.disabled=EditorConfig support is disabled for the project
 editor.notification.enable=Enable
-editor.notification.open.settings=Open settings
\ No newline at end of file
+editor.notification.open.settings=Open settings
+
+scheme.exporter.target.name=EditorConfig File
\ No newline at end of file