diff --git a/src/pattypan/Main.java b/src/pattypan/Main.java index f44ce93..1621052 100644 --- a/src/pattypan/Main.java +++ b/src/pattypan/Main.java @@ -23,6 +23,7 @@ */ package pattypan; +import java.util.ResourceBundle; import java.util.logging.Level; import javafx.application.Application; import javafx.scene.Scene; @@ -59,6 +60,7 @@ public static void main(String[] args) { String wiki = "commons.wikimedia.org"; String protocol = "https://"; String scriptPath = "/w"; + String lang = ""; for (String arg : args) { String[] pair = arg.split("="); if (pair[0].contains("wiki")) { @@ -67,14 +69,16 @@ public static void main(String[] args) { protocol = pair[1]; } else if (pair[0].contains("scriptPath")) { scriptPath = pair[1]; + } else if (pair[0].contains("lang")) { + lang = pair[1]; } } Settings.readProperties(); Session.LOGGER.log(Level.INFO, - "Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}", - new String[]{wiki, protocol, scriptPath} + "Wiki set as: {0}\nProtocol set as: {1}\nScript path set as: {2}\nLanguage set as: {3}", + new String[]{wiki, protocol, scriptPath, lang} ); String os = System.getProperty("os.name"); @@ -84,6 +88,7 @@ public static void main(String[] args) { new String[]{os, Settings.VERSION} ); + Session.LANGUAGE = ResourceBundle.getBundle("pattypan/text/messages" + lang); Session.WIKI = new Wiki(wiki, scriptPath, protocol); launch(args); } diff --git a/src/pattypan/Session.java b/src/pattypan/Session.java index 6ae27a4..52fbc15 100644 --- a/src/pattypan/Session.java +++ b/src/pattypan/Session.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.ResourceBundle; import javafx.scene.Scene; import org.wikipedia.Wiki; import pattypan.LogManager; @@ -54,6 +55,8 @@ public final class Session { public static Wiki WIKI = new Wiki("commons.wikimedia.org"); public static ArrayList FILES_TO_UPLOAD = new ArrayList<>(); + public static ResourceBundle LANGUAGE = ResourceBundle.getBundle("pattypan/text/messages"); + static { WIKI.setUserAgent(Settings.USERAGENT); } diff --git a/src/pattypan/Util.java b/src/pattypan/Util.java index 3623b06..a10850a 100644 --- a/src/pattypan/Util.java +++ b/src/pattypan/Util.java @@ -57,16 +57,19 @@ private Util() {} public static int WINDOW_WIDTH = 750; public static int WINDOW_HEIGHT = 550; - static ResourceBundle bundle = ResourceBundle.getBundle("pattypan/text/messages"); + public static ResourceBundle defaultLanguageBundle = ResourceBundle.getBundle("pattypan/text/messages"); public static String text(String key) { try { - String val = bundle.getString(key); + String val = Session.LANGUAGE.getString(key); return new String(val.getBytes("ISO-8859-1"), "UTF-8"); - } catch (final MissingResourceException ex) { - return ""; - } catch (UnsupportedEncodingException ex) { + } catch (MissingResourceException | UnsupportedEncodingException ex) { + try { + String val = defaultLanguageBundle.getString(key); + return new String(val.getBytes("ISO-8859-1"), "UTF-8"); + } catch (MissingResourceException | UnsupportedEncodingException exe) { return ""; + } } }