diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index fe271af0..f373a56a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -141,7 +141,10 @@ public class AppController implements Initializable { private ToggleGroup theme; @FXML - private ToggleGroup language; + private ToggleGroup languages; + + @FXML + private Menu languagesMenu; @FXML private CheckMenuItem openWalletsInNewWindows; @@ -378,14 +381,7 @@ public class AppController implements Initializable { selectedThemeToggle.ifPresent(toggle -> theme.selectToggle(toggle)); setTheme(null); - Language configLanguage = Config.get().getLanguage(); - if(configLanguage == null) { - configLanguage = LanguagesManager.DEFAULT_LANGUAGE; - Config.get().setLanguage(configLanguage); - } - final Language selectedLanguage = configLanguage; - Optional selectedLanguageToggle = language.getToggles().stream().filter(toggle -> selectedLanguage.equals(toggle.getUserData())).findFirst(); - selectedLanguageToggle.ifPresent(toggle -> language.selectToggle(toggle)); + prepareLanguages(); openWalletsInNewWindowsProperty.set(Config.get().isOpenWalletsInNewWindows()); openWalletsInNewWindows.selectedProperty().bindBidirectional(openWalletsInNewWindowsProperty); @@ -444,6 +440,27 @@ public class AppController implements Initializable { setNetworkLabel(); } + private void prepareLanguages() { + Language[] languagesList = Language.values(); + for(Language language : languagesList) { + RadioMenuItem languageItem = new RadioMenuItem(LanguagesManager.getMessage("language." + language.getCode())); + languageItem.setMnemonicParsing(false); + languageItem.setToggleGroup(languages); + languageItem.setOnAction(this::setLanguage); + languageItem.setUserData(language); + languagesMenu.getItems().add(languageItem); + } + + Language configLanguage = Config.get().getLanguage(); + if(configLanguage == null) { + configLanguage = LanguagesManager.DEFAULT_LANGUAGE; + Config.get().setLanguage(configLanguage); + } + final Language selectedLanguage = configLanguage; + Optional selectedLanguageToggle = languages.getToggles().stream().filter(toggle -> selectedLanguage.equals(toggle.getUserData())).findFirst(); + selectedLanguageToggle.ifPresent(toggle -> languages.selectToggle(toggle)); + } + private void registerShortcuts() { org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent(); if(platform == org.controlsfx.tools.Platform.OSX) { @@ -2358,7 +2375,7 @@ public class AppController implements Initializable { } public void setLanguage(ActionEvent event) { - Language selectedLanguage = (Language)language.getSelectedToggle().getUserData(); + Language selectedLanguage = (Language)languages.getSelectedToggle().getUserData(); if(Config.get().getLanguage() != selectedLanguage) { Config.get().setLanguage(selectedLanguage); } diff --git a/src/main/resources/com/sparrowwallet/sparrow/app.fxml b/src/main/resources/com/sparrowwallet/sparrow/app.fxml index 7bd511f5..06f45c2a 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/app.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/app.fxml @@ -66,7 +66,7 @@ - + @@ -117,20 +117,7 @@ - - - - - - - - - - - - - - +