mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-21 18:16:54 -04:00
display "language" chooser in general preferences
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package org.cryptomator.launcher;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SupportedLanguages {
|
||||
|
||||
// these are BCP 47 language codes, not ISO. Note the "-" instead of the "_":
|
||||
public static List<String> LANGUAGAE_TAGS = List.of("ar", "bn", "bs", "ca", "cs", "de", "el", "es", "fil", "fr", "gl", "he", //
|
||||
"hi", "hr", "hu", "id", "it", "ja", "ko", "lv", "mk", "nb", "nl", "nn", "no", "pa", "pl", "pt", "pt-BR", "ro", "ru", //
|
||||
"sk", "sr", "sr-Latn", "sv", "ta", "te", "th", "tr", "uk", "zh", "zh-HK", "zh-TW");
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import org.cryptomator.common.Environment;
|
||||
import org.cryptomator.common.LicenseHolder;
|
||||
import org.cryptomator.common.settings.Settings;
|
||||
@@ -7,6 +8,7 @@ import org.cryptomator.common.settings.UiTheme;
|
||||
import org.cryptomator.integrations.autostart.AutoStartProvider;
|
||||
import org.cryptomator.integrations.autostart.ToggleAutoStartFailedException;
|
||||
import org.cryptomator.integrations.keychain.KeychainAccessProvider;
|
||||
import org.cryptomator.launcher.SupportedLanguages;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.ui.fxapp.FxApplicationWindows;
|
||||
import org.cryptomator.ui.traymenu.TrayMenuComponent;
|
||||
@@ -27,6 +29,7 @@ import javafx.scene.control.Toggle;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.StringConverter;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
@@ -53,6 +56,7 @@ public class GeneralPreferencesController implements FxController {
|
||||
public CheckBox showMinimizeButtonCheckbox;
|
||||
public CheckBox showTrayIconCheckbox;
|
||||
public CheckBox startHiddenCheckbox;
|
||||
public ChoiceBox<String> preferredLanguageChoiceBox;
|
||||
public CheckBox debugModeCheckbox;
|
||||
public CheckBox autoStartCheckbox;
|
||||
public ToggleGroup nodeOrientation;
|
||||
@@ -90,6 +94,11 @@ public class GeneralPreferencesController implements FxController {
|
||||
|
||||
startHiddenCheckbox.selectedProperty().bindBidirectional(settings.startHidden());
|
||||
|
||||
preferredLanguageChoiceBox.getItems().add(null);
|
||||
preferredLanguageChoiceBox.getItems().addAll(SupportedLanguages.LANGUAGAE_TAGS);
|
||||
preferredLanguageChoiceBox.valueProperty().bindBidirectional(settings.languageProperty());
|
||||
preferredLanguageChoiceBox.setConverter(new LanguageTagConverter(resourceBundle));
|
||||
|
||||
debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode());
|
||||
|
||||
autoStartProvider.ifPresent(autoStart -> autoStartCheckbox.setSelected(autoStart.isEnabled()));
|
||||
@@ -183,6 +192,32 @@ public class GeneralPreferencesController implements FxController {
|
||||
|
||||
}
|
||||
|
||||
private static class LanguageTagConverter extends StringConverter<String> {
|
||||
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
LanguageTagConverter(ResourceBundle resourceBundle) {
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String tag) {
|
||||
if (tag == null) {
|
||||
return resourceBundle.getString("preferences.general.language.auto");
|
||||
} else {
|
||||
var locale = Locale.forLanguageTag(tag);
|
||||
var lang = locale.getDisplayLanguage(locale);
|
||||
var region = locale.getDisplayCountry(locale);
|
||||
return lang + (Strings.isNullOrEmpty(region) ? "" : " (" + region + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fromString(String displayLanguage) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private class KeychainProviderDisplayNameConverter extends StringConverter<KeychainAccessProvider> {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user