Localized strings for errors

This commit is contained in:
Stuart Breckenridge
2021-09-24 09:28:32 +08:00
parent 709d163e9c
commit 25f9896832
2 changed files with 43 additions and 18 deletions

View File

@@ -17,20 +17,34 @@ extension UIViewController {
presentAccountError(accountError, dismiss: dismiss)
} else if let decodingError = error as? DecodingError {
let errorTitle = NSLocalizedString("Error", comment: "Error")
let infromativeText: String = ""
switch decodingError {
case .typeMismatch(let type, _):
let str = "This theme cannot be used because the type—'\(type)'—is mismatched in the Info.plist."
presentError(title: errorTitle, message: str, dismiss: dismiss)
let localizedError = NSLocalizedString("This theme cannot be used because the the type—“%@”—is mismatched in the Info.plist", comment: "Type mismatch")
informativeText = NSString.localizedStringWithFormat(localizedError as NSString, type as! CVarArg) as String
presentError(title: title, message: infromativeText, dismiss: dismiss)
case .valueNotFound(let value, _):
let str = "This theme cannot be used because the value—'\(value)'—is missing in the Info.plist."
presentError(title: errorTitle, message: str, dismiss: dismiss)
let localizedError = NSLocalizedString("This theme cannot be used because the the value—“%@”—is not found in the Info.plist.", comment: "Decoding value missing")
informativeText = NSString.localizedStringWithFormat(localizedError as NSString, value as! CVarArg) as String
presentError(title: title, message: infromativeText, dismiss: dismiss)
case .keyNotFound(let codingKey, _):
let str = "This theme cannot be used because the key—'\(codingKey.stringValue)'—is missing in the Info.plist."
presentError(title: errorTitle, message: str, dismiss: dismiss)
case .dataCorrupted( _):
presentError(title: errorTitle, message: error.localizedDescription, dismiss: dismiss)
let localizedError = NSLocalizedString("This theme cannot be used because the the key—“%@”—is not found in the Info.plist.", comment: "Decoding key missing")
informativeText = NSString.localizedStringWithFormat(localizedError as NSString, codingKey.stringValue) as String
presentError(title: title, message: infromativeText, dismiss: dismiss)
case .dataCorrupted(let context):
guard let error = context.underlyingError as NSError?,
let debugDescription = error.userInfo["NSDebugDescription"] as? String else {
informativeText = error.localizedDescription
presentError(title: title, message: infromativeText, dismiss: dismiss)
return
}
let localizedError = NSLocalizedString("This theme cannot be used because of data corruption in the Info.plist. %@.", comment: "Decoding key missing")
informativeText = NSString.localizedStringWithFormat(localizedError as NSString, debugDescription) as String
presentError(title: title, message: infromativeText, dismiss: dismiss)
default:
presentError(title: errorTitle, message: error.localizedDescription, dismiss: dismiss)
informativeText = error.localizedDescription
presentError(title: title, message: infromativeText, dismiss: dismiss)
}
} else {
let errorTitle = NSLocalizedString("Error", comment: "Error")