Explorar o código

add localization

Armin Schrenk hai 2 meses
pai
achega
8ab038614f

+ 27 - 10
src/main/java/org/cryptomator/ui/decryptname/DecryptFileNamesViewController.java

@@ -5,9 +5,10 @@ import org.cryptomator.common.vaults.Vault;
 import org.cryptomator.cryptofs.common.Constants;
 import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.controls.FontAwesome5Icon;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
-import javax.tools.Tool;
 import javafx.application.Platform;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.ListProperty;
@@ -22,7 +23,6 @@ import javafx.collections.FXCollections;
 import javafx.fxml.FXML;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
-import javafx.scene.control.Tooltip;
 import javafx.scene.control.cell.PropertyValueFactory;
 import javafx.scene.input.Clipboard;
 import javafx.scene.input.DataFormat;
@@ -45,7 +45,11 @@ import java.util.stream.Collectors;
 @DecryptNameScoped
 public class DecryptFileNamesViewController implements FxController {
 
+	private static final Logger LOG = LoggerFactory.getLogger(DecryptFileNamesViewController.class);
 	private static final KeyCodeCombination COPY_TO_CLIPBOARD_SHORTCUT = new KeyCodeCombination(KeyCode.C, KeyCodeCombination.SHORTCUT_DOWN);
+	private static final String COPY_TO_CLIPBOARD_SHORTCUT_STRING_WIN = "CTRL+C";
+	private static final String COPY_TO_CLIPBOARD_SHORTCUT_STRING_MAC = "⌘C";
+	private static final String COPY_TO_CLIPBOARD_SHORTCUT_STRING_LINUX = "CTRL+C";
 
 	private final ListProperty<CipherAndCleartext> mapping;
 	private final StringProperty dropZoneText = new SimpleStringProperty();
@@ -115,14 +119,14 @@ public class DecryptFileNamesViewController implements FxController {
 		ciphertextColumn.setCellValueFactory(new PropertyValueFactory<>("ciphertextFilename"));
 		cleartextColumn.setCellValueFactory(new PropertyValueFactory<>("cleartextName"));
 
-		dropZoneText.setValue("Drop files or click to select");
+		dropZoneText.setValue(resourceBundle.getString("decryptNames.dropZone.message"));
 		dropZoneIcon.setValue(FontAwesome5Icon.FILE_IMPORT);
 
 		wrongFilesSelected.addListener((_, _, areWrongFiles) -> {
 			if (areWrongFiles) {
 				CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS, Platform::runLater).execute(() -> {
 					//dropZoneText.setValue(resourceBundle.getString(".."));
-					dropZoneText.setValue("Drop files or click to select");
+					dropZoneText.setValue(resourceBundle.getString("decryptNames.dropZone.message"));
 					dropZoneIcon.setValue(FontAwesome5Icon.FILE_IMPORT);
 					wrongFilesSelected.setValue(false);
 				});
@@ -136,8 +140,8 @@ public class DecryptFileNamesViewController implements FxController {
 	@FXML
 	public void selectFiles() {
 		var fileChooser = new FileChooser();
-		fileChooser.setTitle(resourceBundle.getString("main.vaultDetail.decryptName.filePickerTitle"));
-		fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Cryptomator encrypted files", List.of("*.c9r", "*.c9s")));
+		fileChooser.setTitle(resourceBundle.getString("decryptNames.filePicker.title"));
+		fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(resourceBundle.getString("decryptNames.filePicker.extensionDescription"), List.of("*.c9r")));
 		fileChooser.setInitialDirectory(vault.getPath().toFile());
 		var ciphertextNodes = fileChooser.showOpenMultipleDialog(window);
 		if (ciphertextNodes != null) {
@@ -150,11 +154,11 @@ public class DecryptFileNamesViewController implements FxController {
 		//Assumption: All files are in the same directory
 		var testPath = pathsToDecrypt.getFirst();
 		if (!testPath.startsWith(vault.getPath())) {
-			setDropZoneError("Selected files do not belong vault %s".formatted(vault.getDisplayName()));
+			setDropZoneError(resourceBundle.getString("decryptNames.dropZone.error.foreignFiles").formatted(vault.getDisplayName()));
 			return;
 		}
 		if (pathsToDecrypt.size() == 1 && testPath.endsWith(Constants.DIR_ID_BACKUP_FILE_NAME)) {
-			setDropZoneError("Vault internal files with no decrypt-able name selected");
+			setDropZoneError(resourceBundle.getString("decryptNames.dropZone.error.vaultInternalFiles"));
 			return;
 		}
 
@@ -162,9 +166,12 @@ public class DecryptFileNamesViewController implements FxController {
 			var newMapping = pathsToDecrypt.stream().filter(p -> !p.endsWith(Constants.DIR_ID_BACKUP_FILE_NAME)).map(this::getCleartextName).toList();
 			mapping.addAll(newMapping);
 		} catch (UncheckedIOException e) {
-			setDropZoneError("Failed to read selected files");
+			setDropZoneError(resourceBundle.getString("decryptNames.dropZone.error.generic"));
+			LOG.info("Failed to decrypt filenames for directory {}", testPath.getParent(), e);
 		} catch (IllegalArgumentException e) {
-			setDropZoneError("Vault internal files with no decrypt-able name selected");
+			setDropZoneError(resourceBundle.getString("decryptNames.dropZone.error.vaultInternalFiles"));
+		} catch (UnsupportedOperationException e) {
+			setDropZoneError(resourceBundle.getString("decryptNames.dropZone.error.noDirIdBackup"));
 		}
 	}
 
@@ -209,4 +216,14 @@ public class DecryptFileNamesViewController implements FxController {
 		var csv = mapping.stream().map(cipherAndClear -> "\"" + cipherAndClear.ciphertext() + "\", \"" + cipherAndClear.cleartextName() + "\"").collect(Collectors.joining("\n"));
 		Clipboard.getSystemClipboard().setContent(Map.of(DataFormat.PLAIN_TEXT, csv));
 	}
+
+	public String getCopyToClipboardShortcutString() {
+		if(SystemUtils.IS_OS_WINDOWS) {
+			return COPY_TO_CLIPBOARD_SHORTCUT_STRING_WIN;
+		} else if(SystemUtils.IS_OS_MAC) {
+			return COPY_TO_CLIPBOARD_SHORTCUT_STRING_MAC;
+		} else {
+			return COPY_TO_CLIPBOARD_SHORTCUT_STRING_LINUX;
+		}
+	}
 }

+ 1 - 2
src/main/java/org/cryptomator/ui/decryptname/DecryptNameModule.java

@@ -32,9 +32,8 @@ public abstract class DecryptNameModule {
 		stage.setResizable(true);
 		stage.initModality(Modality.WINDOW_MODAL);
 		stage.initOwner(owner);
-		stage.setTitle("TODO Decrypt Name");
+		stage.setTitle(resourceBundle.getString("decryptNames.title"));
 		vault.stateProperty().addListener(((_, _, _) -> stage.close())); //as soon as the state changes from unlocked, close the window
-		//stage.setTitle(resourceBundle.getString("convertVault.title"));
 		return stage;
 	}
 

+ 5 - 4
src/main/resources/fxml/decryptnames.fxml

@@ -10,6 +10,7 @@
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.Region?>
 <?import javafx.scene.control.Tooltip?>
+<?import org.cryptomator.ui.controls.FormattedLabel?>
 <VBox xmlns="http://javafx.com/javafx"
 	  xmlns:fx="http://javafx.com/fxml"
 	  fx:controller="org.cryptomator.ui.decryptname.DecryptFileNamesViewController"
@@ -22,12 +23,12 @@
 			<Insets left="6" />
 		</padding>
 		<Region HBox.hgrow="ALWAYS"/>
-		<Button styleClass="button-right" contentDisplay="GRAPHIC_ONLY" onAction="#copyMappingToClipboard">
+		<Button styleClass="button-right" contentDisplay="GRAPHIC_ONLY" onAction="#copyMappingToClipboard"> <!-- TODO: rename method -->
 			<graphic>
 				<FontAwesome5IconView glyph="CLIPBOARD" glyphSize="16"/>
 			</graphic>
 			<tooltip>
-				<Tooltip text="Copy all mappings"/>
+				<Tooltip text="%decryptNames.copyTable.tooltip"/>
 			</tooltip>
 		</Button>
 		<Button styleClass="button-right" contentDisplay="GRAPHIC_ONLY" onAction="#clearTable">
@@ -35,7 +36,7 @@
 				<FontAwesome5IconView glyph="TRASH" glyphSize="16"/>
 			</graphic>
 			<tooltip>
-				<Tooltip text="Clear table"/>
+				<Tooltip text="%decryptNames.clearTable.tooltip"/>
 			</tooltip>
 		</Button>
 	</HBox>
@@ -65,6 +66,6 @@
 			<Insets topRightBottomLeft="6"/>
 		</padding>
 		<Region HBox.hgrow="ALWAYS"/>
-		<Label styleClass="label-small" text="Copy cell content with CTRL+C"/>
+		<FormattedLabel styleClass="label-small" format="%decryptNames.copyHint" arg1="${controller.copyToClipboardShortcutString}"/>
 	</HBox>
 </VBox>

+ 14 - 3
src/main/resources/i18n/strings.properties

@@ -425,9 +425,7 @@ main.vaultDetail.locateEncryptedFileBtn.tooltip=Choose a file from your vault to
 main.vaultDetail.encryptedPathsCopied=Paths Copied to Clipboard!
 main.vaultDetail.locateEncrypted.filePickerTitle=Select File Inside Vault
 main.vaultDetail.decryptName.buttonLabel=Decrypt File Name
-main.vaultDetail.decryptName.filePickerTitle=Select encrypted file
 main.vaultDetail.decryptName.tooltip=Choose an encrypted vault file to decrypt its name
-main.vaultDetail.decryptName.copied=Names copied to clipboard!
 ### Missing
 main.vaultDetail.missing.info=Cryptomator could not find a vault at this path.
 main.vaultDetail.missing.recheck=Recheck
@@ -581,4 +579,17 @@ shareVault.hub.message=How to share a Hub vault
 shareVault.hub.description=In order to share the vault content with another team member, you have to perform two steps:
 shareVault.hub.instruction.1=1. Share access of the encrypted vault folder via cloud storage.
 shareVault.hub.instruction.2=2. Grant access to team member in Cryptomator Hub.
-shareVault.hub.openHub=Open Cryptomator Hub
+shareVault.hub.openHub=Open Cryptomator Hub
+
+# Decrypt File Names
+decryptNames.title=Decrypt File Names
+decryptNames.filePicker.title=Select encrypted file
+decryptNames.filePicker.extensionDescription=Cryptomator encrypted file
+decryptNames.copyTable.tooltip=Copy table
+decryptNames.clearTable.tooltip=Clear table
+decryptNames.copyHint=Copy cell content with %s
+decryptNames.dropZone.message=Drop files or click to select
+decryptNames.dropZone.error.vaultInternalFiles=Vault internal files with no decrypt-able name selected
+decryptNames.dropZone.error.foreignFiles=Files do not belong to vault "%s"
+decryptNames.dropZone.error.noDirIdBackup=Directory of selected files does not contain dirId.c9r file
+decryptNames.dropZone.error.generic=Failed to decrypt file names