Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language switch #74

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/pattypan/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package pattypan;

import java.util.ResourceBundle;
import java.util.logging.Level;
import javafx.application.Application;
import javafx.scene.Scene;
Expand Down Expand Up @@ -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")) {
Expand All @@ -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");
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions src/pattypan/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +55,8 @@ public final class Session {
public static Wiki WIKI = new Wiki("commons.wikimedia.org");
public static ArrayList<UploadElement> FILES_TO_UPLOAD = new ArrayList<>();

public static ResourceBundle LANGUAGE = ResourceBundle.getBundle("pattypan/text/messages");

static {
WIKI.setUserAgent(Settings.USERAGENT);
}
Expand Down
13 changes: 8 additions & 5 deletions src/pattypan/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}
}
}

Expand Down