Localize strings in code
This commit is contained in:
parent
2d5ca58bd9
commit
1b4040135e
36 changed files with 626 additions and 334 deletions
|
|
@ -30,7 +30,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
super.loadView()
|
||||
|
||||
let passcodeLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
|
||||
passcodeLabel.text = "Enter passcode for Pass"
|
||||
passcodeLabel.text = "EnterPasscode".localize()
|
||||
passcodeLabel.font = UIFont.boldSystemFont(ofSize: 18)
|
||||
passcodeLabel.textColor = UIColor.black
|
||||
passcodeLabel.textAlignment = .center
|
||||
|
|
@ -48,7 +48,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
|
||||
let passcodeTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 300, height: 40))
|
||||
passcodeTextField.borderStyle = UITextBorderStyle.roundedRect
|
||||
passcodeTextField.placeholder = "passcode"
|
||||
passcodeTextField.placeholder = "Passcode".localize()
|
||||
passcodeTextField.isSecureTextEntry = true
|
||||
passcodeTextField.clearButtonMode = UITextFieldViewMode.whileEditing
|
||||
passcodeTextField.delegate = self
|
||||
|
|
@ -71,10 +71,10 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
var authError: NSError?
|
||||
if #available(iOS 8.0, macOS 10.12.1, *) {
|
||||
if myContext.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) {
|
||||
var biometryType = "Touch ID"
|
||||
var biometryType = "TouchId".localize()
|
||||
if #available(iOS 11.0, *) {
|
||||
if myContext.biometryType == LABiometryType.faceID {
|
||||
biometryType = "Face ID"
|
||||
biometryType = "FaceId".localize()
|
||||
}
|
||||
}
|
||||
biometryAuthButton.setTitle(biometryType, for: .normal)
|
||||
|
|
@ -83,7 +83,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
}
|
||||
|
||||
let cancelButton = UIButton(type: .custom)
|
||||
cancelButton.setTitle("Cancel", for: .normal)
|
||||
cancelButton.setTitle("Cancel".localize(), for: .normal)
|
||||
cancelButton.setTitleColor(Globals.blue, for: .normal)
|
||||
cancelButton.addTarget(self, action: #selector(passcodeLockDidCancel), for: .touchUpInside)
|
||||
cancelButton.isHidden = !self.isCancellable
|
||||
|
|
@ -167,7 +167,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
|
||||
@objc func bioButtonPressedAction(_ uiButton: UIButton) {
|
||||
let myContext = LAContext()
|
||||
let myLocalizedReasonString = "Authentication is needed to access Pass."
|
||||
let myLocalizedReasonString = "AuthenticationNeeded.".localize()
|
||||
var authError: NSError?
|
||||
|
||||
if #available(iOS 8.0, *) {
|
||||
|
|
@ -188,11 +188,7 @@ open class PasscodeLockViewController: UIViewController, UITextFieldDelegate {
|
|||
if textField == passcodeTextField {
|
||||
if !PasscodeLock.shared.check(passcode: textField.text ?? "") {
|
||||
passcodeFailedAttempts = passcodeFailedAttempts + 1
|
||||
if passcodeFailedAttempts == 1 {
|
||||
passcodeWrongAttemptsLabel?.text = "1 wrong attempt"
|
||||
} else {
|
||||
passcodeWrongAttemptsLabel?.text = "\(passcodeFailedAttempts) wrong attempts"
|
||||
}
|
||||
passcodeWrongAttemptsLabel?.text = "WrongAttempts(%d)".localize(passcodeFailedAttempts)
|
||||
}
|
||||
}
|
||||
textField.resignFirstResponder()
|
||||
|
|
|
|||
|
|
@ -23,27 +23,6 @@ public enum AppError: Error {
|
|||
|
||||
extension AppError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .RepositoryNotSetError:
|
||||
return "Git repository is not set."
|
||||
case let .RepositoryRemoteBranchNotFoundError(remoteBranchName):
|
||||
return "Cannot find remote branch 'origin/\(remoteBranchName)'."
|
||||
case let .RepositoryBranchNotFound(branchName):
|
||||
return "Branch with name '\(branchName)' not found in repository."
|
||||
case .KeyImportError:
|
||||
return "Cannot import the key."
|
||||
case .PasswordDuplicatedError:
|
||||
return "Cannot add the password: password duplicated."
|
||||
case .GitResetError:
|
||||
return "Cannot identify the latest synced commit."
|
||||
case .PGPPublicKeyNotExistError:
|
||||
return "PGP public key doesn't exist."
|
||||
case .WrongPasswordFilename:
|
||||
return "Cannot write to the password file."
|
||||
case .DecryptionError:
|
||||
return "Cannot decrypt password."
|
||||
case .UnknownError:
|
||||
return "Unknown error."
|
||||
}
|
||||
return String(describing: self).localize()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public extension FileManager {
|
|||
fileSize = try fileSize ?? resourceValueForKey(URLResourceKey.fileAllocatedSizeKey)
|
||||
|
||||
guard let size = fileSize else {
|
||||
preconditionFailure("huh? NSURLFileAllocatedSizeKey should always return a value")
|
||||
preconditionFailure("NSURLFileAllocatedSizeKeyShouldAlwaysReturnValue.".localize())
|
||||
}
|
||||
|
||||
// We're good, add up the value.
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class Utils {
|
|||
|
||||
public static func alert(title: String, message: String, controller: UIViewController, handler: ((UIAlertAction) -> Void)? = nil, completion: (() -> Void)? = nil) {
|
||||
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: handler))
|
||||
alert.addAction(UIAlertAction(title: "Ok".localize(), style: UIAlertActionStyle.default, handler: handler))
|
||||
controller.present(alert, animated: true, completion: completion)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,9 +175,9 @@ public class Password {
|
|||
if case let .timer(period) = otpToken!.generator.factor {
|
||||
let timeSinceEpoch = Date().timeIntervalSince1970
|
||||
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
|
||||
description += " (expires in \(validTime)s)"
|
||||
description += " " + "ExpiresIn".localize(validTime)
|
||||
}
|
||||
return (description, otpToken!.currentPassword ?? "error")
|
||||
return (description, otpToken!.currentPassword ?? "Error".localize())
|
||||
}
|
||||
|
||||
// return the password strings
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class PasswordStore {
|
|||
* The store could not be migrated to the current model version.
|
||||
Check the error message to determine what the actual problem was.
|
||||
*/
|
||||
fatalError("Unresolved error \(error), \(error.userInfo)")
|
||||
fatalError("UnresolvedError".localize("\(error.localizedDescription), \(error.userInfo)"))
|
||||
}
|
||||
})
|
||||
return container.viewContext
|
||||
|
|
@ -162,7 +162,7 @@ public class PasswordStore {
|
|||
}
|
||||
try fm.moveItem(atPath: Globals.repositoryPathLegacy, toPath: Globals.repositoryPath)
|
||||
} catch {
|
||||
print("Migration error: \(error)")
|
||||
print("MigrationError".localize(error))
|
||||
}
|
||||
updatePasswordEntityCoreData()
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ public class PasswordStore {
|
|||
return false
|
||||
}
|
||||
} catch {
|
||||
fatalError("Failed to fetch password entities: \(error)")
|
||||
fatalError("FailedToFetchPasswordEntities".localize(error))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -282,7 +282,7 @@ public class PasswordStore {
|
|||
return false
|
||||
}
|
||||
} catch {
|
||||
fatalError("Failed to fetch password entities: \(error)")
|
||||
fatalError("FailedToFetchPasswordEntities".localize(error))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ public class PasswordStore {
|
|||
passwordEntityFetchRequest.predicate = NSPredicate(format: "path = %@ and isDir = %@", path, isDir as NSNumber)
|
||||
return try context.fetch(passwordEntityFetchRequest).first as? PasswordEntity
|
||||
} catch {
|
||||
fatalError("Failed to fetch password entities: \(error)")
|
||||
fatalError("FailedToFetchPasswordEntities".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,7 +417,7 @@ public class PasswordStore {
|
|||
do {
|
||||
try context.save()
|
||||
} catch {
|
||||
print("Error with save: \(error)")
|
||||
print("ErrorSaving".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -445,7 +445,7 @@ public class PasswordStore {
|
|||
let fetchedPasswordEntities = try context.fetch(passwordEntityFetch) as! [PasswordEntity]
|
||||
return fetchedPasswordEntities.sorted { $0.name!.caseInsensitiveCompare($1.name!) == .orderedAscending }
|
||||
} catch {
|
||||
fatalError("Failed to fetch passwords: \(error)")
|
||||
fatalError("FailedToFetchPasswords".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +458,7 @@ public class PasswordStore {
|
|||
let fetchedPasswordEntities = try context.fetch(passwordEntityFetch) as! [PasswordEntity]
|
||||
return fetchedPasswordEntities.sorted { $0.name!.caseInsensitiveCompare($1.name!) == .orderedAscending }
|
||||
} catch {
|
||||
fatalError("Failed to fetch passwords: \(error)")
|
||||
fatalError("FailedToFetchPasswords".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -470,7 +470,7 @@ public class PasswordStore {
|
|||
let passwordEntities = try context.fetch(passwordEntityFetchRequest) as! [PasswordEntity]
|
||||
return passwordEntities
|
||||
} catch {
|
||||
fatalError("Failed to fetch passwords: \(error)")
|
||||
fatalError("FailedToFetchPasswords".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -484,32 +484,32 @@ public class PasswordStore {
|
|||
try context.save()
|
||||
}
|
||||
} catch {
|
||||
fatalError("Failed to save: \(error)")
|
||||
fatalError("ErrorSaving".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
public func getLatestUpdateInfo(filename: String) -> String {
|
||||
guard let storeRepository = storeRepository else {
|
||||
return "Unknown"
|
||||
return "Unknown".localize()
|
||||
}
|
||||
guard let blameHunks = try? storeRepository.blame(withFile: filename, options: nil).hunks,
|
||||
let latestCommitTime = blameHunks.map({
|
||||
$0.finalSignature?.time?.timeIntervalSince1970 ?? 0
|
||||
}).max() else {
|
||||
return "Unknown"
|
||||
return "Unknown".localize()
|
||||
}
|
||||
let lastCommitDate = Date(timeIntervalSince1970: latestCommitTime)
|
||||
let currentDate = Date()
|
||||
var autoFormattedDifference: String
|
||||
if currentDate.timeIntervalSince(lastCommitDate) <= 60 {
|
||||
autoFormattedDifference = "Just now"
|
||||
autoFormattedDifference = "JustNow".localize()
|
||||
} else {
|
||||
let diffDate = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: lastCommitDate, to: currentDate)
|
||||
let dateComponentsFormatter = DateComponentsFormatter()
|
||||
dateComponentsFormatter.unitsStyle = .full
|
||||
dateComponentsFormatter.maximumUnitCount = 2
|
||||
dateComponentsFormatter.includesApproximationPhrase = true
|
||||
autoFormattedDifference = dateComponentsFormatter.string(from: diffDate)!.appending(" ago")
|
||||
autoFormattedDifference = "TimeAgo".localize(dateComponentsFormatter.string(from: diffDate)!)
|
||||
}
|
||||
return autoFormattedDifference
|
||||
}
|
||||
|
|
@ -646,7 +646,7 @@ public class PasswordStore {
|
|||
try self.context.save()
|
||||
ret = passwordEntity
|
||||
} catch {
|
||||
fatalError("Failed to insert a PasswordEntity: \(error)")
|
||||
fatalError("FailedToInsertPasswordEntity".localize(error))
|
||||
}
|
||||
}
|
||||
return ret
|
||||
|
|
@ -658,7 +658,7 @@ public class PasswordStore {
|
|||
let saveURL = storeURL.appendingPathComponent(password.url.path)
|
||||
try self.encrypt(password: password).write(to: saveURL)
|
||||
try gitAdd(path: password.url.path)
|
||||
let _ = try gitCommit(message: "Add password for \(password.url.deletingPathExtension().path) to store using Pass for iOS.")
|
||||
let _ = try gitCommit(message: "AddPassword.".localize(password.url.deletingPathExtension().path))
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
return newPasswordEntity
|
||||
}
|
||||
|
|
@ -668,7 +668,7 @@ public class PasswordStore {
|
|||
try gitRm(path: deletedFileURL.path)
|
||||
try deletePasswordEntities(passwordEntity: passwordEntity)
|
||||
try deleteDirectoryTree(at: deletedFileURL)
|
||||
let _ = try gitCommit(message: "Remove \(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!) from store using Pass for iOS.")
|
||||
let _ = try gitCommit(message: "RemovePassword.".localize(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!))
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
}
|
||||
|
||||
|
|
@ -679,7 +679,7 @@ public class PasswordStore {
|
|||
let saveURL = storeURL.appendingPathComponent(passwordEntity.getURL()!.path)
|
||||
try self.encrypt(password: password).write(to: saveURL)
|
||||
try gitAdd(path: passwordEntity.getURL()!.path)
|
||||
let _ = try gitCommit(message: "Edit password for \(passwordEntity.getURL()!.deletingPathExtension().path.removingPercentEncoding!) using Pass for iOS.")
|
||||
let _ = try gitCommit(message: "EditPassword.".localize(passwordEntity.getURL()!.deletingPathExtension().path.removingPercentEncoding!))
|
||||
newPasswordEntity = passwordEntity
|
||||
newPasswordEntity?.synced = false
|
||||
}
|
||||
|
|
@ -696,8 +696,7 @@ public class PasswordStore {
|
|||
// delete
|
||||
try deleteDirectoryTree(at: deletedFileURL)
|
||||
try deletePasswordEntities(passwordEntity: passwordEntity)
|
||||
let _ = try gitCommit(message: "Rename \(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!) to \(password.url.deletingPathExtension().path.removingPercentEncoding!) using Pass for iOS.")
|
||||
|
||||
let _ = try gitCommit(message: "RenamePassword.".localize(deletedFileURL.deletingPathExtension().path.removingPercentEncoding!, password.url.deletingPathExtension().path.removingPercentEncoding!))
|
||||
}
|
||||
NotificationCenter.default.post(name: .passwordStoreUpdated, object: nil)
|
||||
return newPasswordEntity
|
||||
|
|
@ -712,7 +711,7 @@ public class PasswordStore {
|
|||
do {
|
||||
try self.context.save()
|
||||
} catch {
|
||||
fatalError("Failed to delete a PasswordEntity: \(error)")
|
||||
fatalError("FailedToDeletePasswordEntity".localize(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -721,7 +720,7 @@ public class PasswordStore {
|
|||
do {
|
||||
try context.save()
|
||||
} catch {
|
||||
fatalError("Failed to save a PasswordEntity: \(error)")
|
||||
fatalError("FailedToSavePasswordEntity".localize(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -752,11 +751,11 @@ public class PasswordStore {
|
|||
do {
|
||||
try self.context.save()
|
||||
} catch {
|
||||
fatalError("Failure to save context: \(error)")
|
||||
fatalError("FailureToSaveContext".localize(error))
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
fatalError("Failure to save context: \(error)")
|
||||
fatalError("FailureToSaveContext".localize(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@
|
|||
import OneTimePassword
|
||||
|
||||
public enum OtpType: String {
|
||||
case totp = "time-based"
|
||||
case hotp = "HMAC-based"
|
||||
case none
|
||||
case totp = "TimeBased"
|
||||
case hotp = "HmacBased"
|
||||
case none = "None"
|
||||
|
||||
var description: String {
|
||||
return rawValue
|
||||
return rawValue.localize()
|
||||
}
|
||||
|
||||
init(token: Token?) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue