From 0552d75aa1d9e4e496bd066973fdf59726a4f235 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Tue, 18 Dec 2018 16:30:16 +0530 Subject: Localize all the things Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/UI/TunnelViewModel.swift | 97 ++++++++++++++-------- .../iOS/ViewController/QRScanViewController.swift | 18 ++-- .../SettingsTableViewController.swift | 39 +++++---- .../TunnelDetailTableViewController.swift | 34 ++++---- .../TunnelEditTableViewController.swift | 47 ++++++----- .../TunnelsListTableViewController.swift | 27 +++--- 6 files changed, 148 insertions(+), 114 deletions(-) (limited to 'WireGuard/WireGuard/UI') diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift index 71cb18e..f7ebb68 100644 --- a/WireGuard/WireGuard/UI/TunnelViewModel.swift +++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift @@ -6,29 +6,54 @@ import UIKit //swiftlint:disable:next type_body_length class TunnelViewModel { - enum InterfaceField: String { - case name = "Name" - case privateKey = "Private key" - case publicKey = "Public key" - case generateKeyPair = "Generate keypair" - case addresses = "Addresses" - case listenPort = "Listen port" - case mtu = "MTU" - case dns = "DNS servers" + enum InterfaceField { + case name + case privateKey + case publicKey + case generateKeyPair + case addresses + case listenPort + case mtu + case dns + + var localizedUIString: String { + switch self { + case .name: return tr("tunnelInterfaceName") + case .privateKey: return tr("tunnelInterfacePrivateKey") + case .publicKey: return tr("tunnelInterfacePublicKey") + case .generateKeyPair: return tr("tunnelInterfaceGenerateKeypair") + case .addresses: return tr("tunnelInterfaceAddresses") + case .listenPort: return tr("tunnelInterfaceListenPort") + case .mtu: return tr("tunnelInterfaceMTU") + case .dns: return tr("tunnelInterfaceDNS") + } + } } static let interfaceFieldsWithControl: Set = [ .generateKeyPair ] - enum PeerField: String { - case publicKey = "Public key" - case preSharedKey = "Preshared key" - case endpoint = "Endpoint" - case persistentKeepAlive = "Persistent keepalive" - case allowedIPs = "Allowed IPs" - case excludePrivateIPs = "Exclude private IPs" - case deletePeer = "Delete peer" + enum PeerField { + case publicKey + case preSharedKey + case endpoint + case persistentKeepAlive + case allowedIPs + case excludePrivateIPs + case deletePeer + + var localizedUIString: String { + switch self { + case .publicKey: return tr("tunnelPeerPublicKey") + case .preSharedKey: return tr("tunnelPeerPreSharedKey") + case .endpoint: return tr("tunnelPeerEndpoint") + case .persistentKeepAlive: return tr("tunnelPeerPersistentKeepalive") + case .allowedIPs: return tr("tunnelPeerAllowedIPs") + case .excludePrivateIPs: return tr("tunnelPeerExcludePrivateIPs") + case .deletePeer: return tr("deletePeerButtonTitle") + } + } } static let peerFieldsWithControl: Set = [ @@ -103,15 +128,15 @@ class TunnelViewModel { fieldsWithError.removeAll() guard let name = scratchpad[.name]?.trimmingCharacters(in: .whitespacesAndNewlines), (!name.isEmpty) else { fieldsWithError.insert(.name) - return .error("Interface name is required") + return .error(tr("alertInvalidInterfaceMessageNameRequired")) } guard let privateKeyString = scratchpad[.privateKey] else { fieldsWithError.insert(.privateKey) - return .error("Interface's private key is required") + return .error(tr("alertInvalidInterfaceMessagePrivateKeyRequired")) } guard let privateKey = Data(base64Encoded: privateKeyString), privateKey.count == TunnelConfiguration.keyLength else { fieldsWithError.insert(.privateKey) - return .error("Interface's private key must be a 32-byte key in base64 encoding") + return .error(tr("alertInvalidInterfaceMessagePrivateKeyInvalid")) } var config = InterfaceConfiguration(name: name, privateKey: privateKey) var errorMessages = [String]() @@ -122,7 +147,7 @@ class TunnelViewModel { addresses.append(address) } else { fieldsWithError.insert(.addresses) - errorMessages.append("Interface addresses must be a list of comma-separated IP addresses, optionally in CIDR notation") + errorMessages.append(tr("alertInvalidInterfaceMessageAddressInvalid")) } } config.addresses = addresses @@ -132,7 +157,7 @@ class TunnelViewModel { config.listenPort = listenPort } else { fieldsWithError.insert(.listenPort) - errorMessages.append("Interface's listen port must be between 0 and 65535, or unspecified") + errorMessages.append(tr("alertInvalidInterfaceMessageListenPortInvalid")) } } if let mtuString = scratchpad[.mtu] { @@ -140,7 +165,7 @@ class TunnelViewModel { config.mtu = mtu } else { fieldsWithError.insert(.mtu) - errorMessages.append("Interface's MTU must be between 576 and 65535, or unspecified") + errorMessages.append(tr("alertInvalidInterfaceMessageMTUInvalid")) } } if let dnsString = scratchpad[.dns] { @@ -150,7 +175,7 @@ class TunnelViewModel { dnsServers.append(dnsServer) } else { fieldsWithError.insert(.dns) - errorMessages.append("Interface's DNS servers must be a list of comma-separated IP addresses") + errorMessages.append(tr("alertInvalidInterfaceMessageDNSInvalid")) } } config.dns = dnsServers @@ -243,11 +268,11 @@ class TunnelViewModel { fieldsWithError.removeAll() guard let publicKeyString = scratchpad[.publicKey] else { fieldsWithError.insert(.publicKey) - return .error("Peer's public key is required") + return .error(tr("alertInvalidPeerMessagePublicKeyRequired")) } guard let publicKey = Data(base64Encoded: publicKeyString), publicKey.count == TunnelConfiguration.keyLength else { fieldsWithError.insert(.publicKey) - return .error("Peer's public key must be a 32-byte key in base64 encoding") + return .error(tr("alertInvalidPeerMessagePublicKeyInvalid")) } var config = PeerConfiguration(publicKey: publicKey) var errorMessages = [String]() @@ -256,7 +281,7 @@ class TunnelViewModel { config.preSharedKey = preSharedKey } else { fieldsWithError.insert(.preSharedKey) - errorMessages.append("Peer's preshared key must be a 32-byte key in base64 encoding") + errorMessages.append(tr("alertInvalidPeerMessagePreSharedKeyInvalid")) } } if let allowedIPsString = scratchpad[.allowedIPs] { @@ -266,7 +291,7 @@ class TunnelViewModel { allowedIPs.append(allowedIP) } else { fieldsWithError.insert(.allowedIPs) - errorMessages.append("Peer's allowed IPs must be a list of comma-separated IP addresses, optionally in CIDR notation") + errorMessages.append(tr("alertInvalidPeerMessageAllowedIPsInvalid")) } } config.allowedIPs = allowedIPs @@ -276,7 +301,7 @@ class TunnelViewModel { config.endpoint = endpoint } else { fieldsWithError.insert(.endpoint) - errorMessages.append("Peer's endpoint must be of the form 'host:port' or '[host]:port'") + errorMessages.append(tr("alertInvalidPeerMessageEndpointInvalid")) } } if let persistentKeepAliveString = scratchpad[.persistentKeepAlive] { @@ -284,7 +309,7 @@ class TunnelViewModel { config.persistentKeepAlive = persistentKeepAlive } else { fieldsWithError.insert(.persistentKeepAlive) - errorMessages.append("Peer's persistent keepalive must be between 0 to 65535, or unspecified") + errorMessages.append(tr("alertInvalidPeerMessagePersistentKeepaliveInvalid")) } } @@ -354,7 +379,7 @@ class TunnelViewModel { enum SaveResult { case saved(Configuration) - case error(String) // TODO: Localize error messages + case error(String) } var interfaceData: InterfaceData @@ -425,7 +450,7 @@ class TunnelViewModel { let peerPublicKeysArray = peerConfigurations.map { $0.publicKey } let peerPublicKeysSet = Set(peerPublicKeysArray) if peerPublicKeysArray.count != peerPublicKeysSet.count { - return .error("Two or more peers cannot have the same public key") + return .error(tr("alertInvalidPeerMessagePublicKeyDuplicated")) } let tunnelConfiguration = TunnelConfiguration(interface: interfaceConfiguration, peers: peerConfigurations) @@ -440,13 +465,13 @@ extension TunnelViewModel { static func activateOnDemandOptionText(for activateOnDemandOption: ActivateOnDemandOption) -> String { switch activateOnDemandOption { case .none: - return "Off" + return tr("tunnelOnDemandOptionOff") case .useOnDemandOverWiFiOrCellular: - return "Wi-Fi or cellular" + return tr("tunnelOnDemandOptionWiFiOrCellular") case .useOnDemandOverWiFiOnly: - return "Wi-Fi only" + return tr("tunnelOnDemandOptionWiFiOnly") case .useOnDemandOverCellularOnly: - return "Cellular only" + return tr("tunnelOnDemandOptionCellularOnly") } } diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift index e4b6287..1fd6905 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/QRScanViewController.swift @@ -17,11 +17,11 @@ class QRScanViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - title = "Scan QR code" + title = tr("scanQRCodeViewTitle") navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelTapped)) let tipLabel = UILabel() - tipLabel.text = "Tip: Generate with `qrencode -t ansiutf8 < tunnel.conf`" + tipLabel.text = tr("scanQRCodeTipText") tipLabel.adjustsFontSizeToFitWidth = true tipLabel.textColor = .lightGray tipLabel.textAlignment = .center @@ -39,7 +39,7 @@ class QRScanViewController: UIViewController { let captureSession = captureSession, captureSession.canAddInput(videoInput), captureSession.canAddOutput(metadataOutput) else { - scanDidEncounterError(title: "Camera Unsupported", message: "This device is not able to scan QR codes") + scanDidEncounterError(title: tr("alertScanQRCodeCameraUnsupportedTitle"), message: tr("alertScanQRCodeCameraUnsupportedMessage")) return } @@ -103,16 +103,16 @@ class QRScanViewController: UIViewController { func scanDidComplete(withCode code: String) { let scannedTunnelConfiguration = try? WgQuickConfigFileParser.parse(code, name: "Scanned") guard let tunnelConfiguration = scannedTunnelConfiguration else { - scanDidEncounterError(title: "Invalid QR Code", message: "The scanned QR code is not a valid WireGuard configuration") + scanDidEncounterError(title: tr("alertScanQRCodeInvalidQRCodeTitle"), message: tr("alertScanQRCodeInvalidQRCodeMessage")) return } - let alert = UIAlertController(title: NSLocalizedString("Please name the scanned tunnel", comment: ""), message: nil, preferredStyle: .alert) + let alert = UIAlertController(title: tr("alertScanQRCodeNamePromptTitle"), message: nil, preferredStyle: .alert) alert.addTextField(configurationHandler: nil) - alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel) { [weak self] _ in + alert.addAction(UIAlertAction(title: tr("actionCancel"), style: .cancel) { [weak self] _ in self?.dismiss(animated: true, completion: nil) }) - alert.addAction(UIAlertAction(title: NSLocalizedString("Save", comment: ""), style: .default) { [weak self] _ in + alert.addAction(UIAlertAction(title: tr("actionSave"), style: .default) { [weak self] _ in guard let title = alert.textFields?[0].text?.trimmingCharacters(in: .whitespacesAndNewlines), !title.isEmpty else { return } tunnelConfiguration.interface.name = title if let self = self { @@ -126,7 +126,7 @@ class QRScanViewController: UIViewController { func scanDidEncounterError(title: String, message: String) { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "OK", style: .default) { [weak self] _ in + alertController.addAction(UIAlertAction(title: tr("actionOK"), style: .default) { [weak self] _ in self?.dismiss(animated: true, completion: nil) }) present(alertController, animated: true) @@ -145,7 +145,7 @@ extension QRScanViewController: AVCaptureMetadataOutputObjectsDelegate { guard let metadataObject = metadataObjects.first, let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject, let stringValue = readableObject.stringValue else { - scanDidEncounterError(title: "Invalid Code", message: "The scanned code could not be read") + scanDidEncounterError(title: tr("alertScanQRCodeUnreadableQRCodeTitle"), message: tr("alertScanQRCodeUnreadableQRCodeMessage")) return } diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/SettingsTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/SettingsTableViewController.swift index 65ad2fe..22edcbc 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/SettingsTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/SettingsTableViewController.swift @@ -6,11 +6,20 @@ import os.log class SettingsTableViewController: UITableViewController { - enum SettingsFields: String { - case iosAppVersion = "WireGuard for iOS" - case goBackendVersion = "WireGuard Go Backend" - case exportZipArchive = "Export zip archive" - case exportLogFile = "Export log file" + enum SettingsFields { + case iosAppVersion + case goBackendVersion + case exportZipArchive + case exportLogFile + + var localizedUIString: String { + switch self { + case .iosAppVersion: return tr("settingsVersionKeyWireGuardForIOS") + case .goBackendVersion: return tr("settingsVersionKeyWireGuardGoBackend") + case .exportZipArchive: return tr("settingsExportZipButtonTitle") + case .exportLogFile: return tr("settingsExportLogFileButtonTitle") + } + } } let settingsFieldsBySection: [[SettingsFields]] = [ @@ -33,7 +42,7 @@ class SettingsTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - title = "Settings" + title = tr("settingsViewTitle") navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneTapped)) tableView.estimatedRowHeight = 44 @@ -109,19 +118,19 @@ class SettingsTableViewController: UITableViewController { if FileManager.default.fileExists(atPath: destinationURL.path) { let isDeleted = FileManager.deleteFile(at: destinationURL) if !isDeleted { - ErrorPresenter.showErrorAlert(title: "Log export failed", message: "The pre-existing log could not be cleared", from: self) + ErrorPresenter.showErrorAlert(title: tr("alertUnableToRemovePreviousLogTitle"), message: tr("alertUnableToRemovePreviousLogMessage"), from: self) return } } guard let networkExtensionLogFilePath = FileManager.networkExtensionLogFileURL?.path else { - ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Unable to determine extension log path", from: self) + ErrorPresenter.showErrorAlert(title: tr("alertUnableToFindExtensionLogPathTitle"), message: tr("alertUnableToFindExtensionLogPathMessage"), from: self) return } let isWritten = Logger.global?.writeLog(called: "APP", mergedWith: networkExtensionLogFilePath, called: "NET", to: destinationURL.path) ?? false guard isWritten else { - ErrorPresenter.showErrorAlert(title: "Log export failed", message: "Unable to write logs to file", from: self) + ErrorPresenter.showErrorAlert(title: tr("alertUnableToWriteLogTitle"), message: tr("alertUnableToWriteLogMessage"), from: self) return } @@ -153,11 +162,11 @@ extension SettingsTableViewController { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch section { case 0: - return "About" + return tr("settingsSectionTitleAbout") case 1: - return "Export configurations" + return tr("settingsSectionTitleExportConfigurations") case 2: - return "Tunnel log" + return tr("settingsSectionTitleTunnelLog") default: return nil } @@ -168,7 +177,7 @@ extension SettingsTableViewController { if field == .iosAppVersion || field == .goBackendVersion { let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) cell.copyableGesture = false - cell.key = field.rawValue + cell.key = field.localizedUIString if field == .iosAppVersion { var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown version" if let appBuild = Bundle.main.infoDictionary?["CFBundleVersion"] as? String { @@ -181,7 +190,7 @@ extension SettingsTableViewController { return cell } else if field == .exportZipArchive { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = field.rawValue + cell.buttonText = field.localizedUIString cell.onTapped = { [weak self] in self?.exportConfigurationsAsZipFile(sourceView: cell.button) } @@ -189,7 +198,7 @@ extension SettingsTableViewController { } else { assert(field == .exportLogFile) let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = field.rawValue + cell.buttonText = field.localizedUIString cell.onTapped = { [weak self] in self?.exportLogForLastActivatedTunnel(sourceView: cell.button) } diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift index d3f9c84..50c0e33 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelDetailTableViewController.swift @@ -85,7 +85,7 @@ class TunnelDetailTableViewController: UITableViewController { let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in onConfirmed() } - let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel) let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet) alert.addAction(destroyAction) alert.addAction(cancelAction) @@ -137,13 +137,13 @@ extension TunnelDetailTableViewController { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch sections[section] { case .status: - return "Status" + return tr("tunnelSectionTitleStatus") case .interface: - return "Interface" + return tr("tunnelSectionTitleInterface") case .peer: - return "Peer" + return tr("tunnelSectionTitlePeer") case .onDemand: - return "On-Demand Activation" + return tr("tunnelSectionTitleOnDemand") case .delete: return nil } @@ -171,19 +171,19 @@ extension TunnelDetailTableViewController { let text: String switch status { case .inactive: - text = "Inactive" + text = tr("tunnelStatusInactive") case .activating: - text = "Activating" + text = tr("tunnelStatusActivating") case .active: - text = "Active" + text = tr("tunnelStatusActive") case .deactivating: - text = "Deactivating" + text = tr("tunnelStatusDeactivating") case .reasserting: - text = "Reactivating" + text = tr("tunnelStatusReasserting") case .restarting: - text = "Restarting" + text = tr("tunnelStatusRestarting") case .waiting: - text = "Waiting" + text = tr("tunnelStatusWaiting") } cell.textLabel?.text = text DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(200)) { [weak cell] in @@ -213,7 +213,7 @@ extension TunnelDetailTableViewController { private func interfaceCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { let field = tunnelViewModel.interfaceData.filterFieldsWithValueOrControl(interfaceFields: interfaceFields)[indexPath.row] let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = field.rawValue + cell.key = field.localizedUIString cell.value = tunnelViewModel.interfaceData[field] return cell } @@ -221,14 +221,14 @@ extension TunnelDetailTableViewController { private func peerCell(for tableView: UITableView, at indexPath: IndexPath, with peerData: TunnelViewModel.PeerData) -> UITableViewCell { let field = peerData.filterFieldsWithValueOrControl(peerFields: peerFields)[indexPath.row] let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = field.rawValue + cell.key = field.localizedUIString cell.value = peerData[field] return cell } private func onDemandCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { let cell: KeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = "Activate on demand" + cell.key = tr("tunnelOnDemandKey") cell.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting()) onDemandStatusObservationToken = tunnel.observe(\.isActivateOnDemandEnabled) { [weak cell] tunnel, _ in cell?.value = TunnelViewModel.activateOnDemandDetailText(for: tunnel.activateOnDemandSetting()) @@ -238,11 +238,11 @@ extension TunnelDetailTableViewController { private func deleteConfigurationCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = "Delete tunnel" + cell.buttonText = tr("deleteTunnelButtonTitle") cell.hasDestructiveAction = true cell.onTapped = { [weak self] in guard let self = self else { return } - self.showConfirmationAlert(message: "Delete this tunnel?", buttonTitle: "Delete", from: cell) { [weak self] in + self.showConfirmationAlert(message: tr("deleteTunnelConfirmationAlertMessage"), buttonTitle: tr("deleteTunnelConfirmationAlertButtonTitle"), from: cell) { [weak self] in guard let self = self else { return } self.tunnelsManager.remove(tunnel: self.tunnel) { error in if error != nil { diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift index 4aa1180..3d9724c 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelEditTableViewController.swift @@ -71,7 +71,7 @@ class TunnelEditTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - title = tunnel == nil ? "New configuration" : "Edit configuration" + title = tunnel == nil ? tr("newTunnelViewTitle") : tr("editTunnelViewTitle") navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveTapped)) navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancelTapped)) @@ -98,8 +98,9 @@ class TunnelEditTableViewController: UITableViewController { let tunnelSaveResult = tunnelViewModel.save() switch tunnelSaveResult { case .error(let errorMessage): - let erroringConfiguration = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? "Interface" : "Peer" - ErrorPresenter.showErrorAlert(title: "Invalid \(erroringConfiguration)", message: errorMessage, from: self) + let alertTitle = (tunnelViewModel.interfaceData.validatedConfiguration == nil) ? + tr("alertInvalidInterfaceTitle") : tr("alertInvalidPeerTitle") + ErrorPresenter.showErrorAlert(title: alertTitle, message: errorMessage, from: self) tableView.reloadData() // Highlight erroring fields case .saved(let tunnelConfiguration): if let tunnel = tunnel { @@ -164,13 +165,13 @@ extension TunnelEditTableViewController { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { switch sections[section] { case .interface: - return section == 0 ? "Interface" : nil + return section == 0 ? tr("tunnelSectionTitleInterface") : nil case .peer: - return "Peer" + return tr("tunnelSectionTitlePeer") case .addPeer: return nil case .onDemand: - return "On-Demand Activation" + return tr("tunnelSectionTitleOnDemand") } } @@ -201,7 +202,7 @@ extension TunnelEditTableViewController { private func generateKeyPairCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = field.rawValue + cell.buttonText = field.localizedUIString cell.onTapped = { [weak self] in guard let self = self else { return } @@ -218,24 +219,24 @@ extension TunnelEditTableViewController { private func publicKeyCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell { let cell: TunnelEditKeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = field.rawValue + cell.key = field.localizedUIString cell.value = tunnelViewModel.interfaceData[field] return cell } private func interfaceFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, with field: TunnelViewModel.InterfaceField) -> UITableViewCell { let cell: TunnelEditEditableKeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = field.rawValue + cell.key = field.localizedUIString switch field { case .name, .privateKey: - cell.placeholderText = "Required" + cell.placeholderText = tr("tunnelEditPlaceholderTextRequired") cell.keyboardType = .default case .addresses, .dns: - cell.placeholderText = "Optional" + cell.placeholderText = tr("tunnelEditPlaceholderTextOptional") cell.keyboardType = .numbersAndPunctuation case .listenPort, .mtu: - cell.placeholderText = "Automatic" + cell.placeholderText = tr("tunnelEditPlaceholderTextAutomatic") cell.keyboardType = .numberPad case .publicKey, .generateKeyPair: cell.keyboardType = .default @@ -283,12 +284,12 @@ extension TunnelEditTableViewController { private func deletePeerCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = field.rawValue + cell.buttonText = field.localizedUIString cell.hasDestructiveAction = true cell.onTapped = { [weak self, weak peerData] in guard let peerData = peerData else { return } guard let self = self else { return } - self.showConfirmationAlert(message: "Delete this peer?", buttonTitle: "Delete", from: cell) { [weak self] in + self.showConfirmationAlert(message: tr("deletePeerConfirmationAlertMessage"), buttonTitle: tr("deletePeerConfirmationAlertButtonTitle"), from: cell) { [weak self] in guard let self = self else { return } let removedSectionIndices = self.deletePeer(peer: peerData) let shouldShowExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl) @@ -309,7 +310,7 @@ extension TunnelEditTableViewController { private func excludePrivateIPsCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath) - cell.message = field.rawValue + cell.message = field.localizedUIString cell.isEnabled = peerData.shouldAllowExcludePrivateIPsControl cell.isOn = peerData.excludePrivateIPsValue cell.onSwitchToggled = { [weak self] isOn in @@ -324,20 +325,20 @@ extension TunnelEditTableViewController { private func peerFieldKeyValueCell(for tableView: UITableView, at indexPath: IndexPath, peerData: TunnelViewModel.PeerData, field: TunnelViewModel.PeerField) -> UITableViewCell { let cell: TunnelEditEditableKeyValueCell = tableView.dequeueReusableCell(for: indexPath) - cell.key = field.rawValue + cell.key = field.localizedUIString switch field { case .publicKey: - cell.placeholderText = "Required" + cell.placeholderText = tr("tunnelEditPlaceholderTextRequired") cell.keyboardType = .default case .preSharedKey, .endpoint: - cell.placeholderText = "Optional" + cell.placeholderText = tr("tunnelEditPlaceholderTextOptional") cell.keyboardType = .default case .allowedIPs: - cell.placeholderText = "Optional" + cell.placeholderText = tr("tunnelEditPlaceholderTextOptional") cell.keyboardType = .numbersAndPunctuation case .persistentKeepAlive: - cell.placeholderText = "Off" + cell.placeholderText = tr("tunnelEditPlaceholderTextOff") cell.keyboardType = .numberPad case .excludePrivateIPs, .deletePeer: cell.keyboardType = .default @@ -373,7 +374,7 @@ extension TunnelEditTableViewController { private func addPeerCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath) - cell.buttonText = "Add peer" + cell.buttonText = tr("addPeerButtonTitle") cell.onTapped = { [weak self] in guard let self = self else { return } let shouldHideExcludePrivateIPs = (self.tunnelViewModel.peersData.count == 1 && self.tunnelViewModel.peersData[0].shouldAllowExcludePrivateIPsControl) @@ -394,7 +395,7 @@ extension TunnelEditTableViewController { private func onDemandCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { if indexPath.row == 0 { let cell: SwitchCell = tableView.dequeueReusableCell(for: indexPath) - cell.message = "Activate on demand" + cell.message = tr("tunnelOnDemandKey") cell.isOn = activateOnDemandSetting.isActivateOnDemandEnabled cell.onSwitchToggled = { [weak self] isOn in guard let self = self else { return } @@ -443,7 +444,7 @@ extension TunnelEditTableViewController { let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { _ in onConfirmed() } - let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel) let alert = UIAlertController(title: "", message: message, preferredStyle: .actionSheet) alert.addAction(destroyAction) alert.addAction(cancelAction) diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift index 9dea8b0..fff976f 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift @@ -20,7 +20,7 @@ class TunnelsListTableViewController: UIViewController { let centeredAddButton: BorderedTextButton = { let button = BorderedTextButton() - button.title = "Add a tunnel" + button.title = tr("tunnelsListCenteredAddTunnelButtonTitle") button.isHidden = true return button }() @@ -72,9 +72,9 @@ class TunnelsListTableViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - title = "WireGuard" + title = tr("tunnelsListTitle") navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped(sender:))) - navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Settings", style: .plain, target: self, action: #selector(settingsButtonTapped(sender:))) + navigationItem.leftBarButtonItem = UIBarButtonItem(title: tr("tunnelsListSettingsButtonTitle"), style: .plain, target: self, action: #selector(settingsButtonTapped(sender:))) restorationIdentifier = "TunnelsListVC" } @@ -97,25 +97,25 @@ class TunnelsListTableViewController: UIViewController { @objc func addButtonTapped(sender: AnyObject) { guard tunnelsManager != nil else { return } - let alert = UIAlertController(title: "", message: "Add a new WireGuard tunnel", preferredStyle: .actionSheet) - let importFileAction = UIAlertAction(title: "Create from file or archive", style: .default) { [weak self] _ in + let alert = UIAlertController(title: "", message: tr("addTunnelMenuHeader"), preferredStyle: .actionSheet) + let importFileAction = UIAlertAction(title: tr("addTunnelMenuImportFile"), style: .default) { [weak self] _ in self?.presentViewControllerForFileImport() } alert.addAction(importFileAction) - let scanQRCodeAction = UIAlertAction(title: "Create from QR code", style: .default) { [weak self] _ in + let scanQRCodeAction = UIAlertAction(title: tr("addTunnelMenuQRCode"), style: .default) { [weak self] _ in self?.presentViewControllerForScanningQRCode() } alert.addAction(scanQRCodeAction) - let createFromScratchAction = UIAlertAction(title: "Create from scratch", style: .default) { [weak self] _ in + let createFromScratchAction = UIAlertAction(title: tr("addTunnelMenuFromScratch"), style: .default) { [weak self] _ in if let self = self, let tunnelsManager = self.tunnelsManager { self.presentViewControllerForTunnelCreation(tunnelsManager: tunnelsManager) } } alert.addAction(createFromScratchAction) - let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) + let cancelAction = UIAlertAction(title: tr("actionCancel"), style: .cancel) alert.addAction(cancelAction) if let sender = sender as? UIBarButtonItem { @@ -172,9 +172,9 @@ class TunnelsListTableViewController: UIViewController { completionHandler?() return } - ErrorPresenter.showErrorAlert(title: "Created \(numberSuccessful) tunnels", - message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive", - from: self, onPresented: completionHandler) + let title = tr(format: "alertImportedFromZipTitle (%d)", numberSuccessful) + let message = tr(format: "alertImportedFromZipMessage (%1$d of %2$d)", numberSuccessful, configs.count) + ErrorPresenter.showErrorAlert(title: title, message: message, from: self, onPresented: completionHandler) } } } else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ { @@ -189,8 +189,7 @@ class TunnelsListTableViewController: UIViewController { } } } else { - ErrorPresenter.showErrorAlert(title: "Unable to import tunnel", - message: "An error occured when importing the tunnel configuration.", + ErrorPresenter.showErrorAlert(title: tr("alertUnableToImportTitle"), message: tr("alertUnableToImportMessage"), from: self, onPresented: completionHandler) } } @@ -266,7 +265,7 @@ extension TunnelsListTableViewController: UITableViewDelegate { func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { - let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { [weak self] _, _, completionHandler in + let deleteAction = UIContextualAction(style: .destructive, title: tr("tunnelsListSwipeDeleteButtonTitle")) { [weak self] _, _, completionHandler in guard let tunnelsManager = self?.tunnelsManager else { return } let tunnel = tunnelsManager.tunnel(at: indexPath.row) tunnelsManager.remove(tunnel: tunnel) { error in -- cgit v1.2.3-59-g8ed1b