From b24434571a75f049a28582ee46edac82fed7eaa8 Mon Sep 17 00:00:00 2001 From: dankito Date: Wed, 2 Sep 2020 18:37:07 +0200 Subject: [PATCH] Implemented translating texts for alert to ask user if account should be deleted? --- .../BankingiOSApp/ui/SwiftExtensions.swift | 13 +++++++++++++ .../BankingiOSApp/ui/views/BankListItem.swift | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift index 23d20634..c1c3e10c 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift @@ -21,6 +21,19 @@ extension String { return NSLocalizedString(self, comment: "") } + // TODO: implement passing multiple arguments to localize() +// func localize(_ arguments: CVarArg...) -> String { +// return localize(arguments) +// } +// +// func localize(_ arguments: [CVarArg]) -> String { +// return String(format: NSLocalizedString(self, comment: ""), arguments) +// } + + func localize(_ arguments: CVarArg) -> String { + return String(format: NSLocalizedString(self, comment: ""), arguments) + } + subscript(_ i: Int) -> String { let idx1 = index(startIndex, offsetBy: i) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift index 0f6698a9..9220d39f 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift @@ -49,10 +49,12 @@ struct BankListItem : View { func askUserToDeleteAccount() { // couldn't believe it, .alert() didn't work as SwiftUI resetted @State variable to dislpay it instantly, therefore Alert never got displayed // TODO: use values from Message.createAskUserToDeleteAccountMessage(self.bank, self.deleteAccount) - let alert = UIAlertController(title: "Delete account?", message: "Really delete account '\(bank.displayName)'? This cannot be undone and data will be lost.", preferredStyle: .alert) + let alert = UIAlertController(title: "Delete account?".localize(), + message: "Really delete account '%@'? This cannot be undone and data will be lost.".localize(bank.displayName), + preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { _ in self.deleteAccount(self.bank) } )) - alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) + alert.addAction(UIAlertAction(title: "Delete".localize(), style: .destructive, handler: { _ in self.deleteAccount(self.bank) } )) + alert.addAction(UIAlertAction(title: "Cancel".localize(), style: .cancel, handler: nil)) if let rootViewController = SceneDelegate.rootNavigationController { rootViewController.present(alert, animated: true)