I have below code in swift 3:
class StringUtility {
static func Localizer(tableName: String?) -> (_ key: String, _ params: CVarArg...) -> String {
You cannot pass a variable argument list to another function, you
have to pass a CVaListPointer
instead. Also withVaList
should
be used instead of getVaList
:
class StringResourceUtility {
static func Localizer(tableName: String?) -> (_ key: String, _ params: CVaListPointer) -> String {
return { (key: String, params: CVaListPointer) in
let content = NSLocalizedString(key, tableName: tableName, comment: "")
return NSString(format: content, arguments: params) as String
}
}
}
func localizationHelper(tableName: String, key: String, params: CVarArg...) -> String {
let t = StringResourceUtility.Localizer(tableName: tableName)
return withVaList(params) { t(key, $0) }
}
Example:
let s = localizationHelper(tableName: "table", key: "%@ %@", params: "Wells", "Fargo")
print(s) // Wells Fargo