Skip to content

Commit

Permalink
Merge pull request #278 from rheimus/master
Browse files Browse the repository at this point in the history
#266 Fix single part locale crash
  • Loading branch information
rheimus authored Jul 11, 2021
2 parents 1c566ca + bfc7360 commit 905e4b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/superzanti/serversync/config/JsonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 905e4b0

Please sign in to comment.