From 7fe4251b8809eff5f218a7ac8429ae2ea2ccbc2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Ha=C3=9Flinger?= Date: Sun, 14 Mar 2021 15:32:07 +0100 Subject: [PATCH] Add i18n support for plugin itself --- .../easyi18n/TranslatorToolWindowFactory.java | 9 ++- .../marhali/easyi18n/ui/action/AddAction.java | 7 +- .../easyi18n/ui/action/ReloadAction.java | 5 +- .../easyi18n/ui/action/SearchAction.java | 5 +- .../easyi18n/ui/action/SettingsAction.java | 5 +- .../treeview/CollapseTreeViewAction.java | 6 +- .../action/treeview/ExpandTreeViewAction.java | 6 +- .../marhali/easyi18n/ui/dialog/AddDialog.java | 8 +- .../easyi18n/ui/dialog/EditDialog.java | 8 +- .../easyi18n/ui/dialog/SettingsDialog.java | 9 ++- .../descriptor/DeleteActionDescriptor.java | 3 +- .../marhali/easyi18n/ui/tabs/TableView.java | 3 +- .../de/marhali/easyi18n/ui/tabs/TreeView.java | 3 +- src/main/resources/META-INF/plugin.xml | 4 +- src/main/resources/META-INF/pluginIcon.svg | 76 ++++++++++--------- src/main/resources/messages.properties | 16 ++++ .../resources/messages/MyBundle.properties | 3 - src/main/resources/messages_de.properties | 0 18 files changed, 112 insertions(+), 64 deletions(-) create mode 100644 src/main/resources/messages.properties delete mode 100644 src/main/resources/messages/MyBundle.properties create mode 100644 src/main/resources/messages_de.properties diff --git a/src/main/java/de/marhali/easyi18n/TranslatorToolWindowFactory.java b/src/main/java/de/marhali/easyi18n/TranslatorToolWindowFactory.java index ce6eec8..38efd01 100644 --- a/src/main/java/de/marhali/easyi18n/TranslatorToolWindowFactory.java +++ b/src/main/java/de/marhali/easyi18n/TranslatorToolWindowFactory.java @@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; /** * Tool window factory which will represent the entire ui for this plugin. @@ -30,12 +31,16 @@ public class TranslatorToolWindowFactory implements ToolWindowFactory { // Translations tree view TreeView treeView = new TreeView(project); - Content treeContent = contentFactory.createContent(treeView.getRootPanel(),"TreeView", false); + Content treeContent = contentFactory.createContent(treeView.getRootPanel(), + ResourceBundle.getBundle("messages").getString("view.tree.title"), false); + toolWindow.getContentManager().addContent(treeContent); // Translations table view TableView tableView = new TableView(project); - Content tableContent = contentFactory.createContent(tableView.getRootPanel(), "TableView", false); + Content tableContent = contentFactory.createContent(tableView.getRootPanel(), + ResourceBundle.getBundle("messages").getString("view.table.title"), false); + toolWindow.getContentManager().addContent(tableContent); // ToolWindow Actions (Can be used for every view) diff --git a/src/main/java/de/marhali/easyi18n/ui/action/AddAction.java b/src/main/java/de/marhali/easyi18n/ui/action/AddAction.java index 61365ce..317b971 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/AddAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/AddAction.java @@ -11,6 +11,7 @@ import de.marhali.easyi18n.util.TreeUtil; import org.jetbrains.annotations.NotNull; import javax.swing.tree.TreePath; +import java.util.ResourceBundle; /** * Add translation action. @@ -19,7 +20,8 @@ import javax.swing.tree.TreePath; public class AddAction extends AnAction { public AddAction() { - super("Add Translation", null, AllIcons.General.Add); + super(ResourceBundle.getBundle("messages").getString("action.add"), + null, AllIcons.General.Add); } @Override @@ -34,7 +36,8 @@ public class AddAction extends AnAction { return null; } - if(manager.getToolWindow().getContentManager().getSelectedContent().getDisplayName().equals("TreeView")) { + if(manager.getToolWindow().getContentManager().getSelectedContent() + .getDisplayName().equals(ResourceBundle.getBundle("messages").getString("view.tree.title"))) { TreePath path = manager.getTreeView().getTree().getSelectionPath(); diff --git a/src/main/java/de/marhali/easyi18n/ui/action/ReloadAction.java b/src/main/java/de/marhali/easyi18n/ui/action/ReloadAction.java index a7cbffc..ed7ac40 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/ReloadAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/ReloadAction.java @@ -8,6 +8,8 @@ import de.marhali.easyi18n.service.DataStore; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + /** * Reload translations action. * @author marhali @@ -15,7 +17,8 @@ import org.jetbrains.annotations.NotNull; public class ReloadAction extends AnAction { public ReloadAction() { - super("Reload From Disk", null, AllIcons.Actions.Refresh); + super(ResourceBundle.getBundle("messages").getString("action.reload"), + null, AllIcons.Actions.Refresh); } @Override diff --git a/src/main/java/de/marhali/easyi18n/ui/action/SearchAction.java b/src/main/java/de/marhali/easyi18n/ui/action/SearchAction.java index d078c3e..123a615 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/SearchAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/SearchAction.java @@ -14,6 +14,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.ResourceBundle; import java.util.function.Consumer; /** @@ -26,7 +27,7 @@ public class SearchAction extends AnAction implements CustomComponentAction { private JBTextField textField; public SearchAction(@NotNull Consumer searchCallback) { - super("Search"); + super(ResourceBundle.getBundle("messages").getString("action.search")); this.searchCallback = searchCallback; } @@ -41,7 +42,7 @@ public class SearchAction extends AnAction implements CustomComponentAction { public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) { textField = new JBTextField(); textField.setPreferredSize(new Dimension(160, 25)); - PromptSupport.setPrompt("Search Key...", textField); + PromptSupport.setPrompt(ResourceBundle.getBundle("messages").getString("action.search"), textField); textField.addKeyListener(handleKeyListener()); textField.setBorder(JBUI.Borders.empty()); diff --git a/src/main/java/de/marhali/easyi18n/ui/action/SettingsAction.java b/src/main/java/de/marhali/easyi18n/ui/action/SettingsAction.java index 12ff0a1..6bd209d 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/SettingsAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/SettingsAction.java @@ -6,6 +6,8 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import de.marhali.easyi18n.ui.dialog.SettingsDialog; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + /** * Plugin settings action. * @author marhali @@ -13,7 +15,8 @@ import org.jetbrains.annotations.NotNull; public class SettingsAction extends AnAction { public SettingsAction() { - super("Settings", null, AllIcons.General.Settings); + super(ResourceBundle.getBundle("messages").getString("action.settings"), + null, AllIcons.General.Settings); } @Override diff --git a/src/main/java/de/marhali/easyi18n/ui/action/treeview/CollapseTreeViewAction.java b/src/main/java/de/marhali/easyi18n/ui/action/treeview/CollapseTreeViewAction.java index 6bc00de..0d33a4e 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/treeview/CollapseTreeViewAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/treeview/CollapseTreeViewAction.java @@ -5,6 +5,8 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + /** * Action to collapse all tree nodes with children. * @author marhali @@ -14,7 +16,9 @@ public class CollapseTreeViewAction extends AnAction { private final Runnable collapseRunnable; public CollapseTreeViewAction(Runnable collapseRunnable) { - super("Collapse Tree", null, AllIcons.Actions.Collapseall); + super(ResourceBundle.getBundle("messages").getString("view.tree.collapse"), + null, AllIcons.Actions.Collapseall); + this.collapseRunnable = collapseRunnable; } diff --git a/src/main/java/de/marhali/easyi18n/ui/action/treeview/ExpandTreeViewAction.java b/src/main/java/de/marhali/easyi18n/ui/action/treeview/ExpandTreeViewAction.java index eb1fe99..915e7b4 100644 --- a/src/main/java/de/marhali/easyi18n/ui/action/treeview/ExpandTreeViewAction.java +++ b/src/main/java/de/marhali/easyi18n/ui/action/treeview/ExpandTreeViewAction.java @@ -5,6 +5,8 @@ import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import org.jetbrains.annotations.NotNull; +import java.util.ResourceBundle; + /** * Action to expand the entire tree (open all nodes with children). * @author marhali @@ -14,7 +16,9 @@ public class ExpandTreeViewAction extends AnAction { private final Runnable expandRunnable; public ExpandTreeViewAction(Runnable expandRunnable) { - super("Expand Tree", null, AllIcons.Actions.Expandall); + super(ResourceBundle.getBundle("messages").getString("view.tree.expand"), + null, AllIcons.Actions.Expandall); + this.expandRunnable = expandRunnable; } diff --git a/src/main/java/de/marhali/easyi18n/ui/dialog/AddDialog.java b/src/main/java/de/marhali/easyi18n/ui/dialog/AddDialog.java index d3ebbe9..12527f9 100644 --- a/src/main/java/de/marhali/easyi18n/ui/dialog/AddDialog.java +++ b/src/main/java/de/marhali/easyi18n/ui/dialog/AddDialog.java @@ -16,6 +16,7 @@ import javax.swing.border.EtchedBorder; import java.awt.*; import java.util.HashMap; import java.util.Map; +import java.util.ResourceBundle; /** * Create translation dialog. @@ -64,7 +65,7 @@ public class AddDialog { rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS)); JPanel keyPanel = new JPanel(new GridLayout(0, 1, 2, 2)); - JBLabel keyLabel = new JBLabel("Key"); + JBLabel keyLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("translation.key")); keyTextField = new JBTextField(this.preKey); keyLabel.setLabelFor(keyTextField); keyPanel.add(keyLabel); @@ -85,11 +86,12 @@ public class AddDialog { } JBScrollPane valuePane = new JBScrollPane(valuePanel); - valuePane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Locales")); + valuePane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), + ResourceBundle.getBundle("messages").getString("translation.locales"))); rootPanel.add(valuePane); DialogBuilder builder = new DialogBuilder(); - builder.setTitle("Add Translation"); + builder.setTitle(ResourceBundle.getBundle("messages").getString("action.add")); builder.removeAllActions(); builder.addOkAction(); builder.addCancelAction(); diff --git a/src/main/java/de/marhali/easyi18n/ui/dialog/EditDialog.java b/src/main/java/de/marhali/easyi18n/ui/dialog/EditDialog.java index 6dab340..00884eb 100644 --- a/src/main/java/de/marhali/easyi18n/ui/dialog/EditDialog.java +++ b/src/main/java/de/marhali/easyi18n/ui/dialog/EditDialog.java @@ -17,6 +17,7 @@ import javax.swing.border.EtchedBorder; import java.awt.*; import java.util.HashMap; import java.util.Map; +import java.util.ResourceBundle; /** * Edit translation dialog. @@ -63,7 +64,7 @@ public class EditDialog { rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS)); JPanel keyPanel = new JPanel(new GridLayout(0, 1, 2,2)); - JBLabel keyLabel = new JBLabel("Key"); + JBLabel keyLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("translation.key")); keyTextField = new JBTextField(this.origin.getKey()); keyLabel.setLabelFor(keyTextField); keyPanel.add(keyLabel); @@ -84,11 +85,12 @@ public class EditDialog { } JBScrollPane valuePane = new JBScrollPane(valuePanel); - valuePane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), "Locales")); + valuePane.setBorder(BorderFactory.createTitledBorder(new EtchedBorder(), + ResourceBundle.getBundle("messages").getString("translation.locales"))); rootPanel.add(valuePane); DialogBuilder builder = new DialogBuilder(); - builder.setTitle("Edit Translation"); + builder.setTitle(ResourceBundle.getBundle("messages").getString("action.edit")); builder.removeAllActions(); builder.addCancelAction(); builder.addActionDescriptor(new DeleteActionDescriptor()); diff --git a/src/main/java/de/marhali/easyi18n/ui/dialog/SettingsDialog.java b/src/main/java/de/marhali/easyi18n/ui/dialog/SettingsDialog.java index 8d99065..87a4221 100644 --- a/src/main/java/de/marhali/easyi18n/ui/dialog/SettingsDialog.java +++ b/src/main/java/de/marhali/easyi18n/ui/dialog/SettingsDialog.java @@ -13,6 +13,7 @@ import de.marhali.easyi18n.service.DataStore; import javax.swing.*; import java.awt.*; +import java.util.ResourceBundle; /** * Plugin configuration dialog. @@ -45,17 +46,17 @@ public class SettingsDialog { private DialogBuilder prepare(String localesPath, String previewLocale) { JPanel rootPanel = new JPanel(new GridLayout(0, 1, 2, 2)); - JBLabel pathLabel = new JBLabel("Locales directory"); + JBLabel pathLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.path.text")); pathText = new TextFieldWithBrowseButton(new JTextField(localesPath)); pathLabel.setLabelFor(pathText); - pathText.addBrowseFolderListener("Locales Directory", null, project, new FileChooserDescriptor( + pathText.addBrowseFolderListener(ResourceBundle.getBundle("messages").getString("settings.path.title"), null, project, new FileChooserDescriptor( false, true, false, false, false, false)); rootPanel.add(pathLabel); rootPanel.add(pathText); - JBLabel previewLabel = new JBLabel("Preview locale"); + JBLabel previewLabel = new JBLabel(ResourceBundle.getBundle("messages").getString("settings.preview")); previewText = new JBTextField(previewLocale); previewLabel.setLabelFor(previewText); @@ -63,7 +64,7 @@ public class SettingsDialog { rootPanel.add(previewText); DialogBuilder builder = new DialogBuilder(); - builder.setTitle("Settings"); + builder.setTitle(ResourceBundle.getBundle("messages").getString("action.settings")); builder.removeAllActions(); builder.addCancelAction(); builder.addOkAction(); diff --git a/src/main/java/de/marhali/easyi18n/ui/dialog/descriptor/DeleteActionDescriptor.java b/src/main/java/de/marhali/easyi18n/ui/dialog/descriptor/DeleteActionDescriptor.java index 4c991be..a1cd61e 100644 --- a/src/main/java/de/marhali/easyi18n/ui/dialog/descriptor/DeleteActionDescriptor.java +++ b/src/main/java/de/marhali/easyi18n/ui/dialog/descriptor/DeleteActionDescriptor.java @@ -5,6 +5,7 @@ import com.intellij.openapi.ui.DialogWrapper; import javax.swing.*; import java.awt.event.ActionEvent; +import java.util.ResourceBundle; /** * Delete action which represents the delete button on the edit translation dialog. @@ -18,7 +19,7 @@ public class DeleteActionDescriptor extends AbstractAction implements DialogBuil private DialogWrapper dialogWrapper; public DeleteActionDescriptor() { - super("Delete"); + super(ResourceBundle.getBundle("messages").getString("action.delete")); } @Override diff --git a/src/main/java/de/marhali/easyi18n/ui/tabs/TableView.java b/src/main/java/de/marhali/easyi18n/ui/tabs/TableView.java index 3638686..ef8b00b 100644 --- a/src/main/java/de/marhali/easyi18n/ui/tabs/TableView.java +++ b/src/main/java/de/marhali/easyi18n/ui/tabs/TableView.java @@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.event.MouseEvent; +import java.util.ResourceBundle; /** * Shows translation state as table. @@ -39,7 +40,7 @@ public class TableView implements DataSynchronizer { this.project = project; table = new JBTable(); - table.getEmptyText().setText("Empty"); + table.getEmptyText().setText(ResourceBundle.getBundle("messages").getString("view.empty")); table.addMouseListener(new PopupClickListener(this::handlePopup)); table.addKeyListener(new DeleteKeyListener(handleDeleteKey())); table.setDefaultRenderer(String.class, new TableRenderer()); diff --git a/src/main/java/de/marhali/easyi18n/ui/tabs/TreeView.java b/src/main/java/de/marhali/easyi18n/ui/tabs/TreeView.java index d120d37..4f744d6 100644 --- a/src/main/java/de/marhali/easyi18n/ui/tabs/TreeView.java +++ b/src/main/java/de/marhali/easyi18n/ui/tabs/TreeView.java @@ -28,6 +28,7 @@ import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.awt.event.MouseEvent; +import java.util.ResourceBundle; /** * Show translation state as tree. @@ -49,7 +50,7 @@ public class TreeView implements DataSynchronizer { tree = new Tree(); tree.setCellRenderer(new TreeRenderer()); tree.setRootVisible(false); - tree.getEmptyText().setText("Empty"); + tree.getEmptyText().setText(ResourceBundle.getBundle("messages").getString("view.empty")); tree.addMouseListener(new PopupClickListener(this::handlePopup)); tree.addKeyListener(new DeleteKeyListener(handleDeleteKey())); diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 7f34f55..c68196d 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,6 +1,6 @@ de.marhali.easyi18n - Easy-I18n + easy-i18n marhali @@ -8,7 +8,7 @@ com.intellij.modules.lang - + \ No newline at end of file diff --git a/src/main/resources/META-INF/pluginIcon.svg b/src/main/resources/META-INF/pluginIcon.svg index 6132908..fe60369 100644 --- a/src/main/resources/META-INF/pluginIcon.svg +++ b/src/main/resources/META-INF/pluginIcon.svg @@ -1,45 +1,46 @@ - + + - - - - - + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + + @@ -52,7 +53,10 @@ - - + easy + + i18n + + \ No newline at end of file diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties new file mode 100644 index 0000000..1076225 --- /dev/null +++ b/src/main/resources/messages.properties @@ -0,0 +1,16 @@ +view.tree.title=TreeView +view.tree.collapse=Collapse Tree +view.tree.expand=Expand Tree +view.table.title=TableView +view.empty=No translations found. Click on settings to specify a locales directory or reload +action.add=Add Translation +action.edit=Edit Translation +action.reload=Reload From Disk +action.settings=Settings +action.search=Search Key... +action.delete=Delete +translation.key=Key +translation.locales=Locales +settings.path.title=Locales Directory +settings.path.text=Locales directory +settings.preview=Preview locale \ No newline at end of file diff --git a/src/main/resources/messages/MyBundle.properties b/src/main/resources/messages/MyBundle.properties deleted file mode 100644 index 78dbb24..0000000 --- a/src/main/resources/messages/MyBundle.properties +++ /dev/null @@ -1,3 +0,0 @@ -name=My Plugin -applicationService=Application service -projectService=Project service: {0} diff --git a/src/main/resources/messages_de.properties b/src/main/resources/messages_de.properties new file mode 100644 index 0000000..e69de29