Implemented translating texts for alert to ask user if account should be deleted?

This commit is contained in:
dankito 2020-09-02 18:37:07 +02:00
parent 4607d521b5
commit b24434571a
2 changed files with 18 additions and 3 deletions

View File

@ -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)

View File

@ -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)