From 783c8718c1386cbd4f83d3c2d9e0f9695811420c Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Tue, 25 May 2021 13:20:18 +0200 Subject: [PATCH] add localization for health check names --- .../cryptomator/ui/health/CheckListCell.java | 3 ++- .../ui/health/HealthCheckModule.java | 4 ++-- .../ui/health/HealthCheckTask.java | 19 +++++++++---------- .../main/resources/i18n/strings.properties | 2 ++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/CheckListCell.java b/main/ui/src/main/java/org/cryptomator/ui/health/CheckListCell.java index 73afcfed0..b4863213e 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/health/CheckListCell.java +++ b/main/ui/src/main/java/org/cryptomator/ui/health/CheckListCell.java @@ -26,11 +26,12 @@ class CheckListCell extends ListCell { super.updateItem(item, empty); if (item != null) { - setText(item.getCheck().identifier()); // TODO lookup l18n key + textProperty().bind(item.titleProperty()); item.stateProperty().addListener(this::stateChanged); setGraphic(graphicForState(item.getState())); stateIcon.setGlyph(glyphForState(item.getState())); } else { + textProperty().unbind(); setGraphic(null); setText(null); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckModule.java b/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckModule.java index 0afb3c8bf..e33a9f2f1 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckModule.java @@ -63,8 +63,8 @@ abstract class HealthCheckModule { /* Only inject with Lazy-Wrapper!*/ @Provides @HealthCheckScoped - static Collection provideAvailableHealthCheckTasks(Collection availableHealthChecks, @HealthCheckWindow Vault vault, AtomicReference masterkeyRef, AtomicReference vaultConfigRef, SecureRandom csprng) { - return availableHealthChecks.stream().map(check -> new HealthCheckTask(vault.getPath(), vaultConfigRef.get(), masterkeyRef.get(), csprng, check)).toList(); + static Collection provideAvailableHealthCheckTasks(Collection availableHealthChecks, @HealthCheckWindow Vault vault, AtomicReference masterkeyRef, AtomicReference vaultConfigRef, SecureRandom csprng, ResourceBundle resourceBundle) { + return availableHealthChecks.stream().map(check -> new HealthCheckTask(vault.getPath(), vaultConfigRef.get(), masterkeyRef.get(), csprng, check, resourceBundle)).toList(); } @Provides diff --git a/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckTask.java b/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckTask.java index e7aec4f7a..36543c4bc 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckTask.java +++ b/main/ui/src/main/java/org/cryptomator/ui/health/HealthCheckTask.java @@ -3,7 +3,6 @@ package org.cryptomator.ui.health; import org.cryptomator.cryptofs.VaultConfig; import org.cryptomator.cryptofs.health.api.DiagnosticResult; import org.cryptomator.cryptofs.health.api.HealthCheck; -import org.cryptomator.cryptofs.health.dirid.DirIdCheck; import org.cryptomator.cryptolib.api.Masterkey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,7 +13,9 @@ import javafx.collections.ObservableList; import javafx.concurrent.Task; import java.nio.file.Path; import java.security.SecureRandom; +import java.util.MissingResourceException; import java.util.Objects; +import java.util.ResourceBundle; import java.util.concurrent.CancellationException; class HealthCheckTask extends Task { @@ -28,14 +29,19 @@ class HealthCheckTask extends Task { private final HealthCheck check; private final ObservableList results; - public HealthCheckTask(Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng, HealthCheck check) { + public HealthCheckTask(Path vaultPath, VaultConfig vaultConfig, Masterkey masterkey, SecureRandom csprng, HealthCheck check, ResourceBundle resourceBundle) { this.vaultPath = Objects.requireNonNull(vaultPath); this.vaultConfig = Objects.requireNonNull(vaultConfig); this.masterkey = Objects.requireNonNull(masterkey); this.csprng = Objects.requireNonNull(csprng); this.check = Objects.requireNonNull(check); this.results = FXCollections.observableArrayList(); - updateTitle(getDisplayNameOf(check)); + try { + updateTitle(resourceBundle.getString("health." + check.identifier())); + } catch (MissingResourceException e) { + LOG.warn("Missing proper name for health check {}, falling back to default.", check.identifier()); + updateTitle(check.identifier()); + } } @Override @@ -83,11 +89,4 @@ class HealthCheckTask extends Task { return check; } - static String getDisplayNameOf(HealthCheck check) { - if (check instanceof DirIdCheck) { //TODO: discuss if this should be localized - return "DirectoryCheck"; - } else { - return check.identifier(); - } - } } diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index a245ab42b..aae581cb2 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -154,6 +154,8 @@ health.check.result.noSelectedCheck=For results select a finished check in the l health.check.result.header=Results of %s health.check.export=Export Report health.check.fix=Fix +## Checks +health.org.cryptomator.cryptofs.health.dirid.DirIdCheck=Directory Check # Preferences preferences.title=Preferences