diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 59f75e06..2eb45630 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -115,7 +115,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JButton configSaveDirButton; private static JTextField configRetriesText; private static JCheckBox configAutoupdateCheckbox; - private static JComboBox configLogLevelCombobox; + private static JComboBox configLogLevelCombobox; private static JCheckBox configURLHistoryCheckbox; private static JCheckBox configPlaySound; private static JCheckBox configSaveOrderCheckbox; @@ -127,6 +127,10 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JCheckBox configSaveDescriptions; private static JCheckBox configPreferMp4; private static JCheckBox configWindowPosition; + private static JComboBox configSelectLangComboBox; + private static JLabel configThreadsLabel; + private static JLabel configTimeoutLabel; + private static JLabel configRetriesLabel; private static TrayIcon trayIcon; private static MenuItem trayMenuMain; @@ -136,11 +140,11 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static AbstractRipper ripper; - private ResourceBundle rb = Utils.getResourceBundle(); + private ResourceBundle rb = Utils.getResourceBundle(null); private void updateQueueLabel() { if (queueListModel.size() > 0) { - optionQueue.setText( rb.getString("Queue") + " (" + queueListModel.size() + ")"); + optionQueue.setText(rb.getString("Queue") + " (" + queueListModel.size() + ")"); } else { optionQueue.setText(rb.getString("Queue")); } @@ -471,9 +475,9 @@ public final class MainWindow implements Runnable, RipStatusHandler { // TODO Configuration components configUpdateButton = new JButton(rb.getString("check.for.updates")); configUpdateLabel = new JLabel( rb.getString("current.version") + ": " + UpdateUtils.getThisJarVersion(), JLabel.RIGHT); - JLabel configThreadsLabel = new JLabel(rb.getString("max.download.threads") + ":", JLabel.RIGHT); - JLabel configTimeoutLabel = new JLabel(rb.getString("timeout.mill"), JLabel.RIGHT); - JLabel configRetriesLabel = new JLabel(rb.getString("retry.download.count"), JLabel.RIGHT); + configThreadsLabel = new JLabel(rb.getString("max.download.threads") + ":", JLabel.RIGHT); + configTimeoutLabel = new JLabel(rb.getString("timeout.mill"), JLabel.RIGHT); + configRetriesLabel = new JLabel(rb.getString("retry.download.count"), JLabel.RIGHT); configThreadsText = new JTextField(Integer.toString(Utils.getConfigInteger("threads.size", 3))); configTimeoutText = new JTextField(Integer.toString(Utils.getConfigInteger("download.timeout", 60000))); configRetriesText = new JTextField(Integer.toString(Utils.getConfigInteger("download.retries", 3))); @@ -491,7 +495,8 @@ public final class MainWindow implements Runnable, RipStatusHandler { configWindowPosition = addNewCheckbox(rb.getString("restore.window.position"), "window.position", true); configURLHistoryCheckbox = addNewCheckbox(rb.getString("remember.url.history"), "remember.url_history", true); - configLogLevelCombobox = new JComboBox(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); + configLogLevelCombobox = new JComboBox<>(new String[] {"Log level: Error", "Log level: Warn", "Log level: Info", "Log level: Debug"}); + configSelectLangComboBox = new JComboBox<>(new String[] {"en_US", "de_DE", "es_ES", "fr_CH", "kr_KR", "pt_PT", "fi_FI", "in_ID", "porrisavvo_FI"}); configLogLevelCombobox.setSelectedItem(Utils.getConfigString("log.level", "Log level: Debug")); setLogLevel(configLogLevelCombobox.getSelectedItem().toString()); configSaveDirLabel = new JLabel(); @@ -504,30 +509,22 @@ public final class MainWindow implements Runnable, RipStatusHandler { configSaveDirLabel.setToolTipText(configSaveDirLabel.getText()); configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT); configSaveDirButton = new JButton("Select Save Directory..."); - gbc.gridy = 0; gbc.gridx = 0; configurationPanel.add(configUpdateLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configUpdateButton, gbc); - gbc.gridy = 1; gbc.gridx = 0; configurationPanel.add(configAutoupdateCheckbox, gbc); - gbc.gridx = 1; configurationPanel.add(configLogLevelCombobox, gbc); - gbc.gridy = 2; gbc.gridx = 0; configurationPanel.add(configThreadsLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configThreadsText, gbc); - gbc.gridy = 3; gbc.gridx = 0; configurationPanel.add(configTimeoutLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configTimeoutText, gbc); - gbc.gridy = 4; gbc.gridx = 0; configurationPanel.add(configRetriesLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc); - gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveOrderCheckbox, gbc); - gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveLogs, gbc); - gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveURLsOnly, gbc); - gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configClipboardAutorip, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveAlbumTitles, gbc); - gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDescriptions, gbc); - gbc.gridx = 1; configurationPanel.add(configPreferMp4, gbc); - gbc.gridy = 10; gbc.gridx = 0; configurationPanel.add(configWindowPosition, gbc); - gbc.gridx = 1; configurationPanel.add(configURLHistoryCheckbox, gbc); - gbc.gridy = 11; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc); - gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc); + + addItemToConfigGridBagConstraints(gbc, 0, configUpdateLabel, configUpdateButton); + addItemToConfigGridBagConstraints(gbc, 1, configAutoupdateCheckbox, configLogLevelCombobox); + addItemToConfigGridBagConstraints(gbc, 2, configThreadsLabel, configThreadsText); + addItemToConfigGridBagConstraints(gbc, 3, configTimeoutLabel, configTimeoutText); + addItemToConfigGridBagConstraints(gbc, 4, configRetriesLabel, configRetriesText); + addItemToConfigGridBagConstraints(gbc, 5, configOverwriteCheckbox, configSaveOrderCheckbox); + addItemToConfigGridBagConstraints(gbc, 6, configPlaySound, configSaveLogs); + addItemToConfigGridBagConstraints(gbc, 7, configShowPopup, configSaveURLsOnly); + addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles); + addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4); + addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox); + addItemToConfigGridBagConstraints(gbc, 11, configSelectLangComboBox); + addItemToConfigGridBagConstraints(gbc, 12, configSaveDirLabel, configSaveDirButton); + + emptyPanel = new JPanel(); @@ -550,6 +547,56 @@ public final class MainWindow implements Runnable, RipStatusHandler { gbc.fill = GridBagConstraints.HORIZONTAL; } + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JLabel thing1ToAdd, JButton thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JLabel thing1ToAdd, JTextField thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JCheckBox thing1ToAdd, JCheckBox thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JCheckBox thing1ToAdd, JComboBox thing2ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + gbc.gridx = 1; configurationPanel.add(thing2ToAdd, gbc); + } + + private void addItemToConfigGridBagConstraints(GridBagConstraints gbc, int gbcYValue, JComboBox thing1ToAdd ) { + gbc.gridy = gbcYValue; gbc.gridx = 0; configurationPanel.add(thing1ToAdd, gbc); + } + + private void changeLocale() { + statusLabel.setText(rb.getString("inactive")); + configUpdateButton.setText(rb.getString("check.for.updates")); + configUpdateLabel.setText(rb.getString("current.version") + ": " + UpdateUtils.getThisJarVersion()); + configThreadsLabel.setText(rb.getString("max.download.threads")); + configTimeoutLabel.setText(rb.getString("timeout.mill")); + configRetriesLabel.setText(rb.getString("retry.download.count")); + configOverwriteCheckbox.setText(rb.getString("overwrite.existing.files")); + configAutoupdateCheckbox.setText(rb.getString("auto.update")); + configPlaySound.setText(rb.getString("sound.when.rip.completes")); + configShowPopup.setText(rb.getString("notification.when.rip.starts")); + configSaveOrderCheckbox.setText(rb.getString("preserve.order")); + configSaveLogs.setText(rb.getString("save.logs")); + configSaveURLsOnly.setText(rb.getString("save.urls.only")); + configSaveAlbumTitles.setText(rb.getString("save.album.titles")); + configClipboardAutorip.setText(rb.getString("autorip.from.clipboard")); + configSaveDescriptions.setText(rb.getString("save.descriptions")); + configPreferMp4.setText(rb.getString("prefer.mp4.over.gif")); + configWindowPosition.setText(rb.getString("restore.window.position")); + configURLHistoryCheckbox.setText(rb.getString("remember.url.history")); + optionLog.setText(rb.getString("Log")); + optionHistory.setText(rb.getString("History")); + optionQueue.setText(rb.getString("Queue")); + optionConfiguration.setText(rb.getString("Configuration")); + } + private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); @@ -746,6 +793,11 @@ public final class MainWindow implements Runnable, RipStatusHandler { String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); setLogLevel(level); }); + configSelectLangComboBox.addActionListener(arg0 -> { + String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString(); + rb = Utils.getResourceBundle(level); + changeLocale(); + }); configSaveDirLabel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -897,7 +949,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { new ImageIcon(mainIcon)); if (response == JOptionPane.YES_OPTION) { try { - Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme")); + Desktop.getDesktop().browse(URI.create("http://github.com/ripmeapp/ripme")); } catch (IOException e) { logger.error("Exception while opening project home page", e); } diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 828d552a..e773a305 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -686,18 +686,24 @@ public class Utils { * * @return Returns the default resource bundle using the language specified in the config file. */ - public static ResourceBundle getResourceBundle() { - if (!getConfigString("lang", "").equals("")) { - String[] langCode = getConfigString("lang", "").split("_"); - logger.info("Setting locale to " + getConfigString("lang", "")); + public static ResourceBundle getResourceBundle(String langSelect) { + if (langSelect == null) { + if (!getConfigString("lang", "").equals("")) { + String[] langCode = getConfigString("lang", "").split("_"); + logger.info("Setting locale to " + getConfigString("lang", "")); + return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); + } + } else { + String[] langCode = langSelect.split("_"); + logger.info("Setting locale to " + langSelect); return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); } try { - ResourceBundle rb = ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control()); - return rb; + logger.info("Setting locale to default"); + return ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control()); } catch (MissingResourceException e) { - ResourceBundle rb = ResourceBundle.getBundle("LabelsBundle", Locale.ROOT); - return rb; + logger.info("Setting locale to root"); + return ResourceBundle.getBundle("LabelsBundle", Locale.ROOT); } } } diff --git a/src/main/resources/LabelsBundle.properties b/src/main/resources/LabelsBundle.properties index 3a42ab0c..f991d02f 100644 --- a/src/main/resources/LabelsBundle.properties +++ b/src/main/resources/LabelsBundle.properties @@ -10,7 +10,7 @@ Configuration = Configuration current.version = Current version check.for.updates = Check for updates auto.update = Auto-update? -max.download.threads = Maximum download threads +max.download.threads = Maximum download threads: timeout.mill = Timeout (in milliseconds): retry.download.count = Retry download count overwrite.existing.files = Overwrite existing files? diff --git a/src/main/resources/LabelsBundle_en_US.properties b/src/main/resources/LabelsBundle_en_US.properties new file mode 100644 index 00000000..f991d02f --- /dev/null +++ b/src/main/resources/LabelsBundle_en_US.properties @@ -0,0 +1,37 @@ +Log = Log +History = History +created = created +modified = modified +Queue = Queue +Configuration = Configuration + +# Keys for the Configuration menu + +current.version = Current version +check.for.updates = Check for updates +auto.update = Auto-update? +max.download.threads = Maximum download threads: +timeout.mill = Timeout (in milliseconds): +retry.download.count = Retry download count +overwrite.existing.files = Overwrite existing files? +sound.when.rip.completes = Sound when rip completes +preserve.order = Preserve order +save.logs = Save logs +notification.when.rip.starts = Notification when rip starts +save.urls.only = Save URLs only +save.album.titles = Save album titles +autorip.from.clipboard = Autorip from Clipboard +save.descriptions = Save descriptions +prefer.mp4.over.gif = Prefer MP4 over GIF +restore.window.position = Restore window position +remember.url.history = Remember URL history +loading.history.from = Loading history from + +# Misc UI keys + +loading.history.from.configuration = Loading history from configuration +interrupted.while.waiting.to.rip.next.album = Interrupted while waiting to rip next album +inactive = Inactive +re-rip.checked = Re-rip Checked +remove = Remove +clear = Clear \ No newline at end of file diff --git a/src/main/resources/LabelsBundle_id_ID.properties b/src/main/resources/LabelsBundle_in_ID.properties similarity index 100% rename from src/main/resources/LabelsBundle_id_ID.properties rename to src/main/resources/LabelsBundle_in_ID.properties