瀏覽代碼

add localization for health check names

Armin Schrenk 3 年之前
父節點
當前提交
783c8718c1

+ 2 - 1
main/ui/src/main/java/org/cryptomator/ui/health/CheckListCell.java

@@ -26,11 +26,12 @@ class CheckListCell extends ListCell<HealthCheckTask> {
 		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);
 		}

+ 2 - 2
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<HealthCheckTask> provideAvailableHealthCheckTasks(Collection<HealthCheck> availableHealthChecks, @HealthCheckWindow Vault vault, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, SecureRandom csprng) {
-		return availableHealthChecks.stream().map(check -> new HealthCheckTask(vault.getPath(), vaultConfigRef.get(), masterkeyRef.get(), csprng, check)).toList();
+	static Collection<HealthCheckTask> provideAvailableHealthCheckTasks(Collection<HealthCheck> availableHealthChecks, @HealthCheckWindow Vault vault, AtomicReference<Masterkey> masterkeyRef, AtomicReference<VaultConfig> vaultConfigRef, SecureRandom csprng, ResourceBundle resourceBundle) {
+		return availableHealthChecks.stream().map(check -> new HealthCheckTask(vault.getPath(), vaultConfigRef.get(), masterkeyRef.get(), csprng, check, resourceBundle)).toList();
 	}
 
 	@Provides

+ 9 - 10
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<Void> {
@@ -28,14 +29,19 @@ class HealthCheckTask extends Task<Void> {
 	private final HealthCheck check;
 	private final ObservableList<DiagnosticResult> 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<Void> {
 		return check;
 	}
 
-	static String getDisplayNameOf(HealthCheck check) {
-		if (check instanceof DirIdCheck) { //TODO: discuss if this should be localized
-			return "DirectoryCheck";
-		} else {
-			return check.identifier();
-		}
-	}
 }

+ 2 - 0
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