Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

Commit

Permalink
Added localization and dutch translation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob.v.m committed Jun 9, 2015
1 parent 2cc4a05 commit 70b6696
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 61 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<jre>
<minVersion>1.8.0</minVersion>
</jre>
<icon>${project.build.outputDirectory}/icon.ico</icon>
<icon>${project.build.outputDirectory}/images/icon.ico</icon>
</configuration>
</execution>
</executions>
Expand Down
63 changes: 38 additions & 25 deletions src/main/java/com/jvms/i18neditor/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import com.jvms.i18neditor.event.ResourceEvent;
import com.jvms.i18neditor.event.ResourceListener;
import com.jvms.i18neditor.swing.JScrollablePanel;
import com.jvms.i18neditor.util.MessageBundle;
import com.jvms.i18neditor.util.Resources;
import com.jvms.i18neditor.util.TranslationKeys;

public class Editor extends JFrame {
private static final long serialVersionUID = 1113029729495390082L;

public static final String NAME = "i18n Editor";
public static final String TITLE = "i18n Editor";
public static final String VERSION = "0.1.0-beta.1";
private static final int WINDOW_WIDTH = 1024;
private static final int WINDOW_HEIGHT = 768;
Expand Down Expand Up @@ -77,18 +78,18 @@ public void importResources(String dir) {
setupResource(resource);
} catch (Exception e) {
e.printStackTrace();
showError(String.format("An error occured while opening the resource '%s'.", path.toString()));
showError(MessageBundle.get("resources.open.error.single", path.toString()));
}
});
resourcesDir = Paths.get(dir);
Map<String,String> keys = Maps.newTreeMap();
resources.forEach(resource -> keys.putAll(resource.getTranslations()));
List<String> keyList = Lists.newArrayList(keys.keySet());
translationTree.setModel(new TranslationTreeModel(keyList));
translationTree.setModel(new TranslationTreeModel(MessageBundle.get("translations.model.name"), keyList));
update();
} catch (IOException e) {
e.printStackTrace();
showError("An error occured while opening resources.");
showError(MessageBundle.get("resource.open.error.multiple"));
}
}

Expand All @@ -100,7 +101,7 @@ public void saveResources() {
} catch (Exception e) {
error = true;
e.printStackTrace();
showError(String.format("An error occured while writing the resource '%s'.", resource.getPath().toString()));
showError(MessageBundle.get("resources.write.error.single", resource.getPath().toString()));
}
}
setDirty(error);
Expand Down Expand Up @@ -141,12 +142,12 @@ public void setDirty(boolean dirty) {
}

public void showError(String message) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, message, MessageBundle.get("dialogs.error.title"), JOptionPane.ERROR_MESSAGE);
}

public void showImportDialog() {
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Select Resources Directory");
fc.setDialogTitle(MessageBundle.get("dialogs.import.title"));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = fc.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
Expand All @@ -157,20 +158,23 @@ public void showImportDialog() {
public void showAddResourceDialog(ResourceType type) {
String locale = "";
while (locale != null && locale.isEmpty()) {
locale = (String) JOptionPane.showInputDialog(this, "Enter locale (i.e. en_US):", "Add " + type.toString() + " Resource", JOptionPane.QUESTION_MESSAGE);
locale = (String) JOptionPane.showInputDialog(this,
MessageBundle.get("dialogs.resource.add.text"),
MessageBundle.get("dialogs.resource.add.title", type.toString()),
JOptionPane.QUESTION_MESSAGE);
if (locale != null) {
locale = locale.trim();
Path path = Paths.get(resourcesDir.toString() + "/" + locale);
if (locale.isEmpty() || Files.isDirectory(path)) {
showError("The locale you entered is invalid or does already exist.");
showError(MessageBundle.get("dialogs.resource.add.error.invalid"));
} else {
try {
Resource resource = Resources.create(type, path);
setupResource(resource);
update();
} catch (IOException e) {
e.printStackTrace();
showError("An error occured while creating the new language.");
showError(MessageBundle.get("dialogs.resource.add.error.create"));
}
}
}
Expand All @@ -181,11 +185,14 @@ public void showRenameDialog(String key) {
String name = TranslationKeys.lastPart(key);
String newName = "";
while (newName != null && newName.isEmpty()) {
newName = (String) JOptionPane.showInputDialog(this, "Enter new name:", "Rename Translation", JOptionPane.QUESTION_MESSAGE, null, null, name);
newName = (String) JOptionPane.showInputDialog(this,
MessageBundle.get("dialogs.translation.rename.text"),
MessageBundle.get("dialogs.translation.rename.title"),
JOptionPane.QUESTION_MESSAGE, null, null, name);
if (newName != null) {
newName = newName.trim();
if (newName.isEmpty() || newName.contains(".")) {
showError("The name you entered is invalid.");
showError(MessageBundle.get("dialogs.translation.rename.error"));
} else {
renameTranslationKey(key, newName);
}
Expand All @@ -201,11 +208,14 @@ public void showAddTranslationDialog() {
key = node.getKey();
}
while (newKey != null && newKey.isEmpty()) {
newKey = (String) JOptionPane.showInputDialog(this, "Enter translation key:", "Add Translation", JOptionPane.QUESTION_MESSAGE, null, null, key);
newKey = (String) JOptionPane.showInputDialog(this,
MessageBundle.get("dialogs.translation.add.text"),
MessageBundle.get("dialogs.translation.add.title"),
JOptionPane.QUESTION_MESSAGE, null, null, key);
if (newKey != null) {
newKey = newKey.trim();
if (newKey.isEmpty()) {
showError("The translation key you entered is invalid.");
showError(MessageBundle.get("dialogs.translation.add.error"));
} else {
addTranslationKey(newKey);
}
Expand All @@ -215,7 +225,10 @@ public void showAddTranslationDialog() {

public boolean closeCurrentSession() {
if (isDirty()) {
int result = JOptionPane.showConfirmDialog(this, "You have unsaved changes, do you want to save them?", "Save Translations", JOptionPane.YES_NO_CANCEL_OPTION);
int result = JOptionPane.showConfirmDialog(this,
MessageBundle.get("dialogs.save.text"),
MessageBundle.get("dialogs.save.title"),
JOptionPane.YES_NO_CANCEL_OPTION);
if (result == JOptionPane.YES_OPTION) {
saveResources();
}
Expand Down Expand Up @@ -262,17 +275,17 @@ private void setup() {
contentPane.add(editorMenu, BorderLayout.NORTH);
contentPane.add(contentPanel);

setTitle(NAME);
setTitle(TITLE);
setIconImages(Lists.newArrayList(
new ImageIcon(getClass().getClassLoader().getResource("icon-512.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-256.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-128.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-64.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-48.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-32.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-24.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-20.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("icon-16.png")).getImage()
new ImageIcon(getClass().getClassLoader().getResource("images/icon-512.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-256.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-128.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-64.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-48.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-32.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-24.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-20.png")).getImage(),
new ImageIcon(getClass().getClassLoader().getResource("images/icon-16.png")).getImage()
));
setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
Expand Down
59 changes: 32 additions & 27 deletions src/main/java/com/jvms/i18neditor/EditorMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;

import javax.swing.JMenu;
Expand All @@ -13,11 +12,13 @@
import javax.swing.KeyStroke;

import com.jvms.i18neditor.Resource.ResourceType;
import com.jvms.i18neditor.util.MessageBundle;

public class EditorMenu extends JMenuBar {
private static final long serialVersionUID = -101788804096708514L;

private final Editor editor;

private JMenuItem saveMenuItem;
private JMenuItem reloadMenuItem;
private JMenu translationsMenu;
Expand Down Expand Up @@ -48,34 +49,36 @@ public void setTranslationsMenuEnabled(boolean enabled) {
private void setup() {
int menuShotcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic(KeyEvent.VK_F);
JMenuItem openMenuItem = new JMenuItem("Open Resources...", KeyEvent.VK_O);
JMenu fileMenu = new JMenu(MessageBundle.get("menu.file.title"));
fileMenu.setMnemonic(MessageBundle.getMnemonic("menu.file.vk"));
JMenuItem openMenuItem = new JMenuItem(MessageBundle.get("menu.file.open.title"), MessageBundle.getMnemonic("menu.file.open.vk"));
openMenuItem.setAccelerator(KeyStroke.getKeyStroke('O', menuShotcutKeyMask));
openMenuItem.addActionListener(new OpenMenuItemListener());

addMenu = new JMenu("Add Resource");
addMenu.setMnemonic(KeyEvent.VK_A);
addMenu = new JMenu(MessageBundle.get("menu.file.resource.title"));
addMenu.setMnemonic(MessageBundle.getMnemonic("menu.file.resource.vk"));
addMenu.setEnabled(false);
JMenuItem addJsonResourceMenuItem = new JMenuItem("JSON Format...", KeyEvent.VK_J);

JMenuItem addJsonResourceMenuItem = new JMenuItem(MessageBundle.get("menu.file.resource.json.title"), MessageBundle.getMnemonic("menu.file.resource.json.vk"));
addJsonResourceMenuItem.addActionListener(new AddResourceMenuItemListener(ResourceType.JSON));
JMenuItem addEs6ResourceMenuItem = new JMenuItem("ES6 Format...", KeyEvent.VK_E);
JMenuItem addEs6ResourceMenuItem = new JMenuItem(MessageBundle.get("menu.file.resource.es6.title"), MessageBundle.getMnemonic("menu.file.resource.es6.vk"));
addEs6ResourceMenuItem.addActionListener(new AddResourceMenuItemListener(ResourceType.ES6));

addMenu.add(addJsonResourceMenuItem);
addMenu.add(addEs6ResourceMenuItem);

saveMenuItem = new JMenuItem("Save", KeyEvent.VK_S);
saveMenuItem = new JMenuItem(MessageBundle.get("menu.file.save.title"), MessageBundle.getMnemonic("menu.file.save.vk"));
saveMenuItem.setEnabled(false);
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke('S', menuShotcutKeyMask));
saveMenuItem.addActionListener(new SaveMenuItemListener());

reloadMenuItem = new JMenuItem("Reload", KeyEvent.VK_F5);
reloadMenuItem = new JMenuItem(MessageBundle.get("menu.file.reload.title"), MessageBundle.getMnemonic("menu.file.reload.vk"));
reloadMenuItem.setEnabled(false);
reloadMenuItem.setAccelerator(KeyStroke.getKeyStroke("F5"));
reloadMenuItem.addActionListener(new ReloadMenuItemListener());

JMenuItem exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X);
JMenuItem exitMenuItem = new JMenuItem(MessageBundle.get("menu.file.exit.title"), MessageBundle.getMnemonic("menu.file.exit.vk"));
exitMenuItem.addActionListener(new ExitMenuItemListener());

fileMenu.add(openMenuItem);
Expand All @@ -86,20 +89,20 @@ private void setup() {
fileMenu.addSeparator();
fileMenu.add(exitMenuItem);

translationsMenu = new JMenu("Translations");
translationsMenu = new JMenu(MessageBundle.get("menu.translations.title"));
translationsMenu.setMnemonic(MessageBundle.getMnemonic("menu.translations.vk"));
translationsMenu.setEnabled(false);
translationsMenu.setMnemonic(KeyEvent.VK_R);

JMenuItem addTranslationMenuItem = new JMenuItem("Add Translation...", KeyEvent.VK_T);
JMenuItem addTranslationMenuItem = new JMenuItem(MessageBundle.get("menu.translations.add.title"), MessageBundle.getMnemonic("menu.translations.add.vk"));
addTranslationMenuItem.setAccelerator(KeyStroke.getKeyStroke('T', menuShotcutKeyMask));
addTranslationMenuItem.addActionListener(new AddTranslationMenuItemListener());

translationsMenu.add(addTranslationMenuItem);

JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
JMenu helpMenu = new JMenu(MessageBundle.get("menu.help.title"));
helpMenu.setMnemonic(MessageBundle.getMnemonic("menu.help.vk"));

JMenuItem aboutMenuItem = new JMenuItem("About " + Editor.NAME, KeyEvent.VK_A);
JMenuItem aboutMenuItem = new JMenuItem(MessageBundle.get("menu.help.about.title", Editor.TITLE), MessageBundle.getMnemonic("menu.help.about.vk"));
aboutMenuItem.addActionListener(new AboutMenuItemListener());
helpMenu.add(aboutMenuItem);

Expand Down Expand Up @@ -138,15 +141,17 @@ public void actionPerformed(ActionEvent e) {
private class AboutMenuItemListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(editor,
"<html><body style=\"text-align:center;width:250px;\">"
+ "<hr><br>"
+ "<span style=\"font-weight:bold;font-size:1.2em;\">" + Editor.NAME + "</span><br>"
+ "(version " + Editor.VERSION + ")<br><br>"
+ "<hr><br>"
+ "(c) Copyright 2015<br>Jacob van Mourik<br>MIT Licensed<br><br>"
+ "</body></html>",
"About", JOptionPane.PLAIN_MESSAGE);
String content =
"<html>" +
"<body style=\"text-align:center;width:200px;\"><br>" +
"<span style=\"font-weight:bold;font-size:1.2em;\">" + Editor.TITLE + "</span><br>" +
"v" + Editor.VERSION + "<br><br>" +
"(c) Copyright 2015<br>" +
"Jacob van Mourik<br>" +
"MIT Licensed<br><br>" +
"</body>" +
"</html>";
JOptionPane.showMessageDialog(editor, content, MessageBundle.get("dialogs.about.title", Editor.TITLE), JOptionPane.PLAIN_MESSAGE);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jvms/i18neditor/ResourceField.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jvms.i18neditor;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
Expand Down Expand Up @@ -50,7 +51,7 @@ private void setup() {
// Add undo support
getDocument().addUndoableEditListener(new EditListener());
getActionMap().put("undo", new UndoAction());
getInputMap().put(KeyStroke.getKeyStroke("ctrl Z"), "undo");
getInputMap().put(KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "undo");
}

@SuppressWarnings("serial")
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/jvms/i18neditor/TranslationTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.swing.tree.TreePath;

import com.google.common.collect.Lists;
import com.jvms.i18neditor.util.MessageBundle;
import com.jvms.i18neditor.util.TranslationKeys;

public class TranslationTree extends JTree {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/jvms/i18neditor/TranslationTreeMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import com.jvms.i18neditor.util.MessageBundle;

public class TranslationTreeMenu extends JPopupMenu {
private static final long serialVersionUID = -4407236120087907574L;

Expand All @@ -18,7 +20,7 @@ public TranslationTreeMenu(Editor editor) {
}

private void setup() {
JMenuItem addMenuItem = new JMenuItem("Add Translation...");
JMenuItem addMenuItem = new JMenuItem(MessageBundle.get("menu.translations.add.title"));
addMenuItem.addActionListener(new AddMenuItemListener());
add(addMenuItem);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/jvms/i18neditor/TranslationTreeModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

public class TranslationTreeModel extends DefaultTreeModel {
private static final long serialVersionUID = 3261808274177599488L;

public TranslationTreeModel() {
super(null);
}

public TranslationTreeModel(List<String> keys) {
super(new TranslationTreeNode("Translations", keys));
public TranslationTreeModel(String rootName, List<String> keys) {
super(new TranslationTreeNode(rootName, keys));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;

import com.jvms.i18neditor.util.MessageBundle;

public class TranslationTreeNodeMenu extends JPopupMenu {
private static final long serialVersionUID = -4407236120087907574L;

Expand All @@ -21,19 +23,19 @@ public TranslationTreeNodeMenu(Editor editor, TranslationTreeNode node) {
}

private void setup() {
JMenuItem addMenuItem = new JMenuItem("Add Translation...");
JMenuItem addMenuItem = new JMenuItem(MessageBundle.get("menu.translations.add.title"));
addMenuItem.addActionListener(new AddMenuItemListener());
add(addMenuItem);

if (!node.isRoot()) {
addSeparator();

JMenuItem renameMenuItem = new JMenuItem("Rename...");
JMenuItem renameMenuItem = new JMenuItem(MessageBundle.get("menu.translations.rename.title"));
renameMenuItem.setAccelerator(KeyStroke.getKeyStroke("F2"));
renameMenuItem.addActionListener(new RenameMenuItemListener());
add(renameMenuItem);

JMenuItem deleteMenuItem = new JMenuItem("Delete");
JMenuItem deleteMenuItem = new JMenuItem(MessageBundle.get("menu.translations.delete.title"));
deleteMenuItem.setAccelerator(KeyStroke.getKeyStroke("DELETE"));
deleteMenuItem.addActionListener(new DeleteMenuItemListener());
add(deleteMenuItem);
Expand Down
Loading

0 comments on commit 70b6696

Please sign in to comment.