Skip to content

Commit

Permalink
Finishes localization flow
Browse files Browse the repository at this point in the history
  • Loading branch information
edimoral committed Mar 4, 2024
1 parent 4f832a3 commit 9c557a2
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 121 deletions.
12 changes: 6 additions & 6 deletions src/main/java/jpass/ui/EntryDetailsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import jpass.util.DateUtils;
import jpass.xml.bind.Entry;

import static jpass.ui.JPassFrame.MESSAGES;
import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.util.Constants.VIEW_WINDOW_CREATED;
import static jpass.util.Constants.VIEW_WINDOW_MODIFIED;
import static jpass.util.Constants.VIEW_WINDOW_TITLE;
Expand All @@ -61,11 +61,11 @@ public class EntryDetailsTable extends JTable {
= DateUtils.createFormatter(Configuration.getInstance().get("date.format", "yyyy-MM-dd"));

private enum DetailType {
TITLE(MESSAGES.getString(VIEW_WINDOW_TITLE), Entry::getTitle),
URL(MESSAGES.getString(VIEW_WINDOW_URL), Entry::getUrl),
USER(MESSAGES.getString(VIEW_WINDOW_USER), Entry::getUser),
MODIFIED(MESSAGES.getString(VIEW_WINDOW_MODIFIED), entry -> DateUtils.formatIsoDateTime(entry.getLastModification(), FORMATTER)),
CREATED(MESSAGES.getString(VIEW_WINDOW_CREATED), entry -> DateUtils.formatIsoDateTime(entry.getCreationDate(), FORMATTER));
TITLE(localizedMessages.getString(VIEW_WINDOW_TITLE), Entry::getTitle),
URL(localizedMessages.getString(VIEW_WINDOW_URL), Entry::getUrl),
USER(localizedMessages.getString(VIEW_WINDOW_USER), Entry::getUser),
MODIFIED(localizedMessages.getString(VIEW_WINDOW_MODIFIED), entry -> DateUtils.formatIsoDateTime(entry.getLastModification(), FORMATTER)),
CREATED(localizedMessages.getString(VIEW_WINDOW_CREATED), entry -> DateUtils.formatIsoDateTime(entry.getCreationDate(), FORMATTER));

private final String description;
private final Function<Entry, String> valueMapper;
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/jpass/ui/EntryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@
import jpass.util.StringUtils;
import jpass.xml.bind.Entry;

import static jpass.ui.JPassFrame.MESSAGES;
import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.ui.helper.EntryHelper.copyEntryField;
import static jpass.util.Constants.BUTTON_MESSAGE_CANCEL;
import static jpass.util.Constants.BUTTON_MESSAGE_OK;
import static jpass.util.Constants.ENTRY_DIALOG_COPY_ENTRY;
import static jpass.util.Constants.ENTRY_DIALOG_FILL_TITLE_FIELD;
import static jpass.util.Constants.ENTRY_DIALOG_GENERATE_ENTRY;
import static jpass.util.Constants.ENTRY_DIALOG_SHOW_ENTRY;
import static jpass.util.Constants.ENTRY_DIALOG_TITLE_ALREADY_EXISTS;
import static jpass.util.Constants.PASSWORD_PASSWORDS_NOT_IDENTICAL;
import static jpass.util.Constants.VIEW_WINDOW_NOTES;
import static jpass.util.Constants.VIEW_WINDOW_PASSWORD;
import static jpass.util.Constants.VIEW_WINDOW_REPEAT;
Expand Down Expand Up @@ -126,15 +129,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr
this.originalEcho = this.passwordField.getEchoChar();
this.repeatField = TextComponentFactory.newPasswordField(true);

this.showButton = new JToggleButton(MESSAGES.getString(ENTRY_DIALOG_SHOW_ENTRY), MessageDialog.getIcon("show"));
this.showButton = new JToggleButton(localizedMessages.getString(ENTRY_DIALOG_SHOW_ENTRY), MessageDialog.getIcon("show"));
this.showButton.setActionCommand("show_button");
this.showButton.setMnemonic(KeyEvent.VK_S);
this.showButton.addActionListener(this);
this.generateButton = new JButton(MESSAGES.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton.setActionCommand("generate_button");
this.generateButton.setMnemonic(KeyEvent.VK_G);
this.generateButton.addActionListener(this);
this.copyButton = new JButton(MESSAGES.getString(ENTRY_DIALOG_COPY_ENTRY), MessageDialog.getIcon("keyring"));
this.copyButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_COPY_ENTRY), MessageDialog.getIcon("keyring"));
this.copyButton.setActionCommand("copy_button");
this.copyButton.setMnemonic(KeyEvent.VK_P);
this.copyButton.addActionListener(this);
Expand All @@ -149,15 +152,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr
5, 0); // xPad, yPad

this.fieldPanel = new JPanel(new SpringLayout());
this.fieldPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_TITLE))));
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_TITLE))));
this.fieldPanel.add(this.titleField);
this.fieldPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_URL))));
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_URL))));
this.fieldPanel.add(this.urlField);
this.fieldPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_USER_NAME))));
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_USER_NAME))));
this.fieldPanel.add(this.userField);
this.fieldPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_PASSWORD))));
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_PASSWORD))));
this.fieldPanel.add(this.passwordField);
this.fieldPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_REPEAT))));
this.fieldPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_REPEAT))));
this.fieldPanel.add(this.repeatField);
this.fieldPanel.add(new JLabel(""));
this.fieldPanel.add(this.passwordButtonPanel);
Expand All @@ -173,15 +176,15 @@ public EntryDialog(JPassFrame parent, String title, Entry entry, boolean newEntr

this.notesPanel = new JPanel(new BorderLayout(5, 5));
this.notesPanel.setBorder(new EmptyBorder(0, 5, 0, 5));
this.notesPanel.add(new JLabel(String.format("%s:", MESSAGES.getString(VIEW_WINDOW_NOTES))), BorderLayout.NORTH);
this.notesPanel.add(new JLabel(String.format("%s:", localizedMessages.getString(VIEW_WINDOW_NOTES))), BorderLayout.NORTH);
this.notesPanel.add(new JScrollPane(this.notesField), BorderLayout.CENTER);

this.okButton = new JButton(MESSAGES.getString(BUTTON_MESSAGE_OK), MessageDialog.getIcon("accept"));
this.okButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_OK), MessageDialog.getIcon("accept"));
this.okButton.setActionCommand("ok_button");
this.okButton.setMnemonic(KeyEvent.VK_O);
this.okButton.addActionListener(this);

this.cancelButton = new JButton(MESSAGES.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton.setActionCommand("cancel_button");
this.cancelButton.setMnemonic(KeyEvent.VK_C);
this.cancelButton.addActionListener(this);
Expand Down Expand Up @@ -209,13 +212,13 @@ public void actionPerformed(ActionEvent e) {
this.repeatField.setEchoChar(this.showButton.isSelected() ? NULL_ECHO : this.originalEcho);
} else if ("ok_button".equals(command)) {
if (this.titleField.getText().trim().isEmpty()) {
MessageDialog.showWarningMessage(this, "Please fill the title field.");
MessageDialog.showWarningMessage(this, localizedMessages.getString(ENTRY_DIALOG_FILL_TITLE_FIELD));
return;
} else if (!checkEntryTitle()) {
MessageDialog.showWarningMessage(this, "Title is already exists,\nplease enter a different title.");
MessageDialog.showWarningMessage(this, localizedMessages.getString(ENTRY_DIALOG_TITLE_ALREADY_EXISTS));
return;
} else if (!Arrays.equals(this.passwordField.getPassword(), this.repeatField.getPassword())) {
MessageDialog.showWarningMessage(this, "Password and repeated passwords are not identical.");
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_PASSWORDS_NOT_IDENTICAL));
return;
}
this.modifiedEntry = getEntryFromDialog();
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/jpass/ui/GeneratePasswordDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@
import javax.swing.border.TitledBorder;

import jpass.util.Configuration;
import jpass.util.Constants;
import jpass.util.CryptUtils;
import jpass.util.SpringUtilities;

import static jpass.ui.JPassFrame.MESSAGES;
import static jpass.ui.JPassFrame.localizedMessages;
import static jpass.util.Constants.BUTTON_MESSAGE_ACCEPT;
import static jpass.util.Constants.BUTTON_MESSAGE_CANCEL;
import static jpass.util.Constants.BUTTON_MESSAGE_CLOSE;
Expand Down Expand Up @@ -88,9 +87,9 @@ public final class GeneratePasswordDialog extends JDialog implements ActionListe
* Options for password generation.
*/
private static final String[][] PASSWORD_OPTIONS = {
{MESSAGES.getString(VIEW_WINDOW_UPPER_CASE_LETTERS), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
{MESSAGES.getString(VIEW_WINDOW_LOWER_CASE_LETTERS), "abcdefghijklmnopqrstuvwxyz"},
{MESSAGES.getString(VIEW_WINDOW_NUMBERS), "0123456789"}
{localizedMessages.getString(VIEW_WINDOW_UPPER_CASE_LETTERS), "ABCDEFGHIJKLMNOPQRSTUVWXYZ"},
{localizedMessages.getString(VIEW_WINDOW_LOWER_CASE_LETTERS), "abcdefghijklmnopqrstuvwxyz"},
{localizedMessages.getString(VIEW_WINDOW_NUMBERS), "0123456789"}
};

private JCheckBox[] checkBoxes;
Expand Down Expand Up @@ -145,12 +144,12 @@ public GeneratePasswordDialog(JDialog parent) {
*/
private void initDialog(final Component parent, final boolean showAcceptButton) {
setModal(true);
setTitle(MESSAGES.getString(PASSWORD_GENERATE_PASSWORD));
setTitle(localizedMessages.getString(PASSWORD_GENERATE_PASSWORD));
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.generatedPassword = null;

this.lengthPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
this.lengthLabel = new JLabel(String.format("%s:", MESSAGES.getString(PASSWORD_PASSWORD_LENGTH)));
this.lengthLabel = new JLabel(String.format("%s:", localizedMessages.getString(PASSWORD_PASSWORD_LENGTH)));
this.lengthPanel.add(this.lengthLabel);

int passwordGenerationLength = Configuration.getInstance().getInteger("default.password.generation.length", 14);
Expand All @@ -165,14 +164,14 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
this.lengthPanel.add(this.lengthSpinner);

this.charactersPanel = new JPanel();
this.charactersPanel.setBorder(new TitledBorder(MESSAGES.getString(VIEW_WINDOW_SETTINGS)));
this.charactersPanel.setBorder(new TitledBorder(localizedMessages.getString(VIEW_WINDOW_SETTINGS)));
this.charactersPanel.add(this.lengthPanel);
this.checkBoxes = new JCheckBox[PASSWORD_OPTIONS.length];
for (int i = 0; i < PASSWORD_OPTIONS.length; i++) {
this.checkBoxes[i] = new JCheckBox(PASSWORD_OPTIONS[i][0], true);
this.charactersPanel.add(this.checkBoxes[i]);
}
this.customSymbolsCheck = new JCheckBox(MESSAGES.getString(VIEW_WINDOW_CUSTOM_SYMBOLS));
this.customSymbolsCheck = new JCheckBox(localizedMessages.getString(VIEW_WINDOW_CUSTOM_SYMBOLS));
this.customSymbolsCheck.setActionCommand("custom_symbols_check");
this.customSymbolsCheck.addActionListener(this);
this.charactersPanel.add(this.customSymbolsCheck);
Expand All @@ -184,11 +183,11 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
SpringUtilities.makeCompactGrid(this.charactersPanel, 6, 1, 5, 5, 5, 5);

this.passwordPanel = new JPanel(new BorderLayout());
this.passwordPanel.setBorder(new TitledBorder(MESSAGES.getString(PASSWORD_GENERATED_PASSWORD)));
this.passwordPanel.setBorder(new TitledBorder(localizedMessages.getString(PASSWORD_GENERATED_PASSWORD)));

this.passwordField = TextComponentFactory.newTextField();
this.passwordPanel.add(this.passwordField, BorderLayout.NORTH);
this.generateButton = new JButton(MESSAGES.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton = new JButton(localizedMessages.getString(ENTRY_DIALOG_GENERATE_ENTRY), MessageDialog.getIcon("generate"));
this.generateButton.setActionCommand("generate_button");
this.generateButton.addActionListener(this);
this.generateButton.setMnemonic(KeyEvent.VK_G);
Expand All @@ -199,15 +198,15 @@ private void initDialog(final Component parent, final boolean showAcceptButton)
this.buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

if (showAcceptButton) {
this.acceptButton = new JButton(MESSAGES.getString(BUTTON_MESSAGE_ACCEPT), MessageDialog.getIcon("accept"));
this.acceptButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_ACCEPT), MessageDialog.getIcon("accept"));
this.acceptButton.setActionCommand("accept_button");
this.acceptButton.setMnemonic(KeyEvent.VK_A);
this.acceptButton.addActionListener(this);
this.buttonPanel.add(this.acceptButton);

this.cancelButton = new JButton(MESSAGES.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CANCEL), MessageDialog.getIcon("cancel"));
} else {
this.cancelButton = new JButton(MESSAGES.getString(BUTTON_MESSAGE_CLOSE), MessageDialog.getIcon("close"));
this.cancelButton = new JButton(localizedMessages.getString(BUTTON_MESSAGE_CLOSE), MessageDialog.getIcon("close"));
}

this.cancelButton.setActionCommand("cancel_button");
Expand Down Expand Up @@ -248,7 +247,7 @@ public void actionPerformed(ActionEvent e) {
}

if (characterSet.isEmpty()) {
MessageDialog.showWarningMessage(this, MESSAGES.getString(PASSWORD_CAN_NOT_GENERATE_PASSWORD));
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_CAN_NOT_GENERATE_PASSWORD));
return;
}

Expand All @@ -261,7 +260,7 @@ public void actionPerformed(ActionEvent e) {
} else if ("accept_button".equals(command)) {
this.generatedPassword = this.passwordField.getText();
if (this.generatedPassword.isEmpty()) {
MessageDialog.showWarningMessage(this, MESSAGES.getString(PASSWORD_GENERATE_PASSWORD_REQUEST));
MessageDialog.showWarningMessage(this, localizedMessages.getString(PASSWORD_GENERATE_PASSWORD_REQUEST));
return;
}
dispose();
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/jpass/ui/JPassFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import static jpass.util.Constants.EDIT_MENU;
import static jpass.util.Constants.FILE_MENU;
import static jpass.util.Constants.HELP_MENU;
import static jpass.util.Constants.PANEL_SAVE_MODIFIED_QUESTION_MESSAGE;
import static jpass.util.Constants.TOOLS_MENU;

/**
Expand All @@ -80,7 +81,7 @@
*/
public final class JPassFrame extends JFrame {

public static ResourceBundle MESSAGES = null;
public static ResourceBundle localizedMessages = null;
private static final Logger LOG = Logger.getLogger(JPassFrame.class.getName());

private static JPassFrame instance;
Expand Down Expand Up @@ -113,7 +114,7 @@ private JPassFrame(String fileName, Locale locale) {
LOG.log(Level.CONFIG, "Could not set application icon.", e);
}

MESSAGES = ResourceBundle.getBundle("resources.languages.Messages", locale);
localizedMessages = ResourceBundle.getBundle("resources.languages.languages", locale);

this.toolBar = new JToolBar();
this.toolBar.setFloatable(false);
Expand Down Expand Up @@ -146,7 +147,7 @@ private JPassFrame(String fileName, Locale locale) {

this.jpassMenuBar = new JMenuBar();

this.fileMenu = new JMenu(MESSAGES.getString(FILE_MENU));
this.fileMenu = new JMenu(localizedMessages.getString(FILE_MENU));
this.fileMenu.setMnemonic(KeyEvent.VK_F);
this.fileMenu.add(MenuActionType.NEW_FILE.getAction());
this.fileMenu.add(MenuActionType.OPEN_FILE.getAction());
Expand All @@ -161,7 +162,7 @@ private JPassFrame(String fileName, Locale locale) {
this.fileMenu.add(MenuActionType.EXIT.getAction());
this.jpassMenuBar.add(this.fileMenu);

this.editMenu = new JMenu(MESSAGES.getString(EDIT_MENU));
this.editMenu = new JMenu(localizedMessages.getString(EDIT_MENU));
this.editMenu.setMnemonic(KeyEvent.VK_E);
this.editMenu.add(MenuActionType.ADD_ENTRY.getAction());
this.editMenu.add(MenuActionType.EDIT_ENTRY.getAction());
Expand All @@ -175,13 +176,13 @@ private JPassFrame(String fileName, Locale locale) {
this.editMenu.add(MenuActionType.FIND_ENTRY.getAction());
this.jpassMenuBar.add(this.editMenu);

this.toolsMenu = new JMenu(MESSAGES.getString(TOOLS_MENU));
this.toolsMenu = new JMenu(localizedMessages.getString(TOOLS_MENU));
this.toolsMenu.setMnemonic(KeyEvent.VK_T);
this.toolsMenu.add(MenuActionType.GENERATE_PASSWORD.getAction());
this.toolsMenu.add(MenuActionType.CLEAR_CLIPBOARD.getAction());
this.jpassMenuBar.add(this.toolsMenu);

this.helpMenu = new JMenu(MESSAGES.getString(HELP_MENU));
this.helpMenu = new JMenu(localizedMessages.getString(HELP_MENU));
this.helpMenu.setMnemonic(KeyEvent.VK_H);
this.helpMenu.add(MenuActionType.LICENSE.getAction());
this.helpMenu.addSeparator();
Expand Down Expand Up @@ -231,7 +232,7 @@ public static JPassFrame getInstance() {

public static synchronized JPassFrame getInstance(String fileName) {
if (instance == null) {
Locale locale = new Locale("es", "US");
Locale locale = new Locale("es", "MX");
instance = new JPassFrame(fileName, locale);
}
return instance;
Expand Down Expand Up @@ -298,9 +299,9 @@ public void refreshEntryTitleList(String selectTitle) {
}

if (searchCriteria.isEmpty()) {
this.statusPanel.setText(String.format("%s: %d", MESSAGES.getString(BOTTOM_MENU_ENTRIES_COUNT), entries.size()));
this.statusPanel.setText(String.format("%s: %d", localizedMessages.getString(BOTTOM_MENU_ENTRIES_COUNT), entries.size()));
} else {
this.statusPanel.setText(String.format("%s: %d / %d", MESSAGES.getString(BOTTOM_MENU_ENTRIES_FOUND), this.entryDetailsTable.getRowCount(), entries.size()));
this.statusPanel.setText(String.format("%s: %d / %d", localizedMessages.getString(BOTTOM_MENU_ENTRIES_FOUND), this.entryDetailsTable.getRowCount(), entries.size()));
}
}

Expand All @@ -323,7 +324,7 @@ public void exitFrame() {
return;
}
if (this.model.isModified()) {
int option = showQuestionMessage(this, FileHelper.SAVE_MODIFIED_QUESTION_MESSAGE, YES_NO_CANCEL_OPTION);
int option = showQuestionMessage(this, localizedMessages.getString(PANEL_SAVE_MODIFIED_QUESTION_MESSAGE), YES_NO_CANCEL_OPTION);
if (option == YES_OPTION) {
FileHelper.saveFile(this, false, () -> System.exit(0));
return;
Expand Down
Loading

0 comments on commit 9c557a2

Please sign in to comment.