You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hop.apache.org by ha...@apache.org on 2021/03/27 15:25:35 UTC
[incubator-hop] branch master updated: HOP-2666 - Fix hardcoded
strings in ProjectsConfigOptionPlugin Little refactoring to introduce a new
class TranslateUtil to support translation in annotation by using the
i18n:: tag
This is an automated email from the ASF dual-hosted git repository.
hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git
The following commit(s) were added to refs/heads/master by this push:
new f9837e1 HOP-2666 - Fix hardcoded strings in ProjectsConfigOptionPlugin Little refactoring to introduce a new class TranslateUtil to support translation in annotation by using the i18n:: tag
new e8cca46 Merge pull request #708 from sramazzina/HOP-2666
f9837e1 is described below
commit f9837e1a2e10d7f1c311b847982fc3a24a50b762
Author: sergio.ramazzina <se...@serasoft.it>
AuthorDate: Fri Mar 26 17:33:59 2021 +0100
HOP-2666 - Fix hardcoded strings in ProjectsConfigOptionPlugin
Little refactoring to introduce a new class TranslateUtil to support translation in annotation by using the i18n:: tag
---
.../apache/hop/core/gui/plugin/GuiRegistry.java | 28 ++-----------
.../org/apache/hop/core/util/TranslateUtil.java | 48 ++++++++++++++++++++++
.../config/ProjectsConfigOptionPlugin.java | 2 +-
.../hop/ui/core/dialog/EnterOptionsDialog.java | 3 +-
4 files changed, 55 insertions(+), 26 deletions(-)
diff --git a/core/src/main/java/org/apache/hop/core/gui/plugin/GuiRegistry.java b/core/src/main/java/org/apache/hop/core/gui/plugin/GuiRegistry.java
index cbea15c..e92ceaf 100644
--- a/core/src/main/java/org/apache/hop/core/gui/plugin/GuiRegistry.java
+++ b/core/src/main/java/org/apache/hop/core/gui/plugin/GuiRegistry.java
@@ -30,6 +30,7 @@ import org.apache.hop.core.gui.plugin.menu.GuiMenuElement;
import org.apache.hop.core.gui.plugin.menu.GuiMenuItem;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement;
import org.apache.hop.core.gui.plugin.toolbar.GuiToolbarItem;
+import org.apache.hop.core.util.TranslateUtil;
import org.apache.hop.i18n.BaseMessages;
import java.lang.reflect.Field;
@@ -396,9 +397,9 @@ public class GuiRegistry {
public void addGuiContextAction(
String guiPluginClassName, Method method, GuiContextAction ca, ClassLoader classLoader) {
- String name = translate(ca.name(), method.getDeclaringClass());
- String category = translate(ca.category(), method.getDeclaringClass());
- String tooltip = translate(ca.tooltip(), method.getDeclaringClass());
+ String name = TranslateUtil.translate(ca.name(), method.getDeclaringClass());
+ String category = TranslateUtil.translate(ca.category(), method.getDeclaringClass());
+ String tooltip = TranslateUtil.translate(ca.tooltip(), method.getDeclaringClass());
GuiAction action =
new GuiAction(
@@ -413,27 +414,6 @@ public class GuiRegistry {
actions.add(action);
}
- private String translate(String name, Class<?> parentObjectClass) {
- if (name.startsWith(Const.I18N_PREFIX)) {
- String[] parts = name.split(":");
- if (parts.length != 3) {
- return name;
- }
-
- String packageName = parts[1];
- String key = parts[2];
-
- String translation;
- if (StringUtils.isEmpty(packageName)) {
- translation = BaseMessages.getString(parentObjectClass, key);
- } else {
- translation = BaseMessages.getString(packageName, key);
- }
- return translation;
- } else {
- return name;
- }
- }
public List<GuiAction> getGuiContextActions(String parentContextId) {
return contextActionsMap.get(parentContextId);
}
diff --git a/core/src/main/java/org/apache/hop/core/util/TranslateUtil.java b/core/src/main/java/org/apache/hop/core/util/TranslateUtil.java
new file mode 100644
index 0000000..9b13d7c
--- /dev/null
+++ b/core/src/main/java/org/apache/hop/core/util/TranslateUtil.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.core.util;
+
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hop.core.Const;
+import org.apache.hop.i18n.BaseMessages;
+
+public class TranslateUtil {
+
+ public static String translate(String name, Class<?> parentObjectClass) {
+ if (name.startsWith(Const.I18N_PREFIX)) {
+ String[] parts = name.split(":");
+ if (parts.length != 3) {
+ return name;
+ }
+
+ String packageName = parts[1];
+ String key = parts[2];
+
+ String translation;
+ if (StringUtils.isEmpty(packageName)) {
+ translation = BaseMessages.getString(parentObjectClass, key);
+ } else {
+ translation = BaseMessages.getString(packageName, key);
+ }
+ return translation;
+ } else {
+ return name;
+ }
+ }
+}
diff --git a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java
index 41628ed..a263832 100644
--- a/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java
+++ b/plugins/misc/projects/src/main/java/org/apache/hop/projects/config/ProjectsConfigOptionPlugin.java
@@ -41,7 +41,7 @@ import picocli.CommandLine;
id = "ProjectsConfigOptionPlugin",
description = "Configuration options for the global projects plugin")
@GuiPlugin(
- description = "Projects" // Tab label in options dialog
+ description = "i18n::ProjectConfig.Tab.Name" // Tab label in options dialog
)
public class ProjectsConfigOptionPlugin
implements IConfigOptions, IGuiPluginCompositeWidgetsListener {
diff --git a/ui/src/main/java/org/apache/hop/ui/core/dialog/EnterOptionsDialog.java b/ui/src/main/java/org/apache/hop/ui/core/dialog/EnterOptionsDialog.java
index 6f306ea..b8b3b49 100644
--- a/ui/src/main/java/org/apache/hop/ui/core/dialog/EnterOptionsDialog.java
+++ b/ui/src/main/java/org/apache/hop/ui/core/dialog/EnterOptionsDialog.java
@@ -25,6 +25,7 @@ import org.apache.hop.core.gui.plugin.GuiPlugin;
import org.apache.hop.core.plugins.IPlugin;
import org.apache.hop.core.plugins.PluginRegistry;
import org.apache.hop.core.util.EnvUtil;
+import org.apache.hop.core.util.TranslateUtil;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.i18n.GlobalMessages;
import org.apache.hop.i18n.LanguageChoice;
@@ -1250,7 +1251,7 @@ public class EnterOptionsDialog extends Dialog {
// Add a tab
//
CTabItem wPluginTab = new CTabItem(wTabFolder, SWT.NONE);
- wPluginTab.setText(Const.NVL(annotation.description(), ""));
+ wPluginTab.setText(Const.NVL(TranslateUtil.translate(annotation.description(), emptySourceData.getClass()), ""));
ScrolledComposite sOtherComp =
new ScrolledComposite(wTabFolder, SWT.V_SCROLL | SWT.H_SCROLL);