From bfc7360e46faf1c71dbbbe0acd3c70ef147e1d03 Mon Sep 17 00:00:00 2001 From: Rheimus Date: Sun, 11 Jul 2021 14:02:09 +1200 Subject: [PATCH] #266 Fix single part locales crash --- .../serversync/GUIJavaFX/PaneOptions.java | 13 ++++++------- .../superzanti/serversync/config/JsonConfig.java | 13 +++++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/superzanti/serversync/GUIJavaFX/PaneOptions.java b/src/main/java/com/superzanti/serversync/GUIJavaFX/PaneOptions.java index 57fa177..3dcef92 100644 --- a/src/main/java/com/superzanti/serversync/GUIJavaFX/PaneOptions.java +++ b/src/main/java/com/superzanti/serversync/GUIJavaFX/PaneOptions.java @@ -13,7 +13,6 @@ import javafx.scene.layout.GridPane; import javafx.scene.text.Font; -import java.io.File; import java.io.IOException; import java.util.Date; import java.util.Locale; @@ -238,17 +237,17 @@ private void changeLanguage(String language) { private void setDefaultComboxBox(){ Locale locale = SyncConfig.getConfig().LOCALE; - if (locale.equals(new Locale("en", "US"))) { + if (locale.equals(new Locale("en", "US")) || locale.equals(new Locale("en"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/english")); - } else if (locale.equals(new Locale("es", "ES"))) { + } else if (locale.equals(new Locale("es", "ES")) || locale.equals(new Locale("es"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/spanish")); - } else if (locale.equals(new Locale("fr", "FR"))) { + } else if (locale.equals(new Locale("fr", "FR")) || locale.equals(new Locale("fr"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/french")); - } else if (locale.equals(new Locale("pl", "PL"))) { + } else if (locale.equals(new Locale("pl", "PL")) || locale.equals(new Locale("pl"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/polish")); - } else if (locale.equals(new Locale("ru", "RU"))) { + } else if (locale.equals(new Locale("ru", "RU")) || locale.equals(new Locale("ru"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/russian")); - } else if (locale.equals(new Locale("zh", "CN"))) { + } else if (locale.equals(new Locale("zh", "CN")) || locale.equals(new Locale("zh"))) { comboBoxLanguage.getSelectionModel().select(ServerSync.strings.getString("language/chinese")); } } diff --git a/src/main/java/com/superzanti/serversync/config/JsonConfig.java b/src/main/java/com/superzanti/serversync/config/JsonConfig.java index 384daf4..d5b9738 100644 --- a/src/main/java/com/superzanti/serversync/config/JsonConfig.java +++ b/src/main/java/com/superzanti/serversync/config/JsonConfig.java @@ -169,8 +169,17 @@ public static void forClient(Path json) throws IOException { hasMissingEntries = true; } - String[] localeParts = getString(misc, PROP_LOCALE, "en_US").split("_"); - config.LOCALE = new Locale(localeParts[0], localeParts[1]); + String locale = getString(misc, PROP_LOCALE, "en_US"); + String[] localeParts = locale.split("_"); + if (localeParts.length == 1) { + config.LOCALE = new Locale(localeParts[0]); + } + if (localeParts.length == 2) { + config.LOCALE = new Locale(localeParts[0], localeParts[1]); + } + if (localeParts.length > 2) { + Logger.error(String.format("Unknown locale pattern: %s", locale)); + } config.THEME = ETheme.valueOf(getString(misc, PROP_THEME, "BLUE_YELLOW")); if (hasMissingEntries) {