带变量的 NSLocalizedString(key: value: comment: ) 在 swift 中不起作用
NSLocalizedString(key: value: comment: ) with variable is not working in swift
我需要本地化一个有一些变量的字符串,本地化的字符串必须用 key: value: comment 格式定义。伙计们,我尝试了很多方法,但还没有找到正确的方法。看这里...
let timeValue = 5
let timeString = "hours"
//Bellows are working fine
dateLabelString = String(format: "Overdue by %d %@", timeValue,timeString) //Working //Normal flat string
dateLabelString = String(format: NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Working
dateLabelString = String.localizedStringWithFormat(NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Working
dateLabelString = NSString.init(format: "Overdue by %d %@", timeValue,timeString) as String //Working
dateLabelString = NSString.init(format: NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) as String //Working
//Bellows are not working
dateLabelString = String(format: NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Not Working
dateLabelString = String.localizedStringWithFormat(NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Not Working
dateLabelString = NSString.init(format: NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) as String //Not Working
Xcode: 8.2.1 Swift: 2.3
Notice the problem is for including the key on NSLocalizedString, otherwise its working perfectly. I need the key must.
对于带有变量的本地化字符串,这对我有用:
String.localizedStringWithFormat(NSLocalizedString("MyCustomKey", comment: "Hello %d World"), myValue)
并且在 Localizable.strings
这一行中:
MyCustomKey = "Hello %d World";
我需要本地化一个有一些变量的字符串,本地化的字符串必须用 key: value: comment 格式定义。伙计们,我尝试了很多方法,但还没有找到正确的方法。看这里...
let timeValue = 5
let timeString = "hours"
//Bellows are working fine
dateLabelString = String(format: "Overdue by %d %@", timeValue,timeString) //Working //Normal flat string
dateLabelString = String(format: NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Working
dateLabelString = String.localizedStringWithFormat(NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Working
dateLabelString = NSString.init(format: "Overdue by %d %@", timeValue,timeString) as String //Working
dateLabelString = NSString.init(format: NSLocalizedString("Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) as String //Working
//Bellows are not working
dateLabelString = String(format: NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Not Working
dateLabelString = String.localizedStringWithFormat(NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) //Not Working
dateLabelString = NSString.init(format: NSLocalizedString("OVERDUE_BY", value: "Overdue by %d %@", comment: "Overdue by 5 days/hours/minutes/seconds"), timeValue,timeString) as String //Not Working
Xcode: 8.2.1 Swift: 2.3
Notice the problem is for including the key on NSLocalizedString, otherwise its working perfectly. I need the key must.
对于带有变量的本地化字符串,这对我有用:
String.localizedStringWithFormat(NSLocalizedString("MyCustomKey", comment: "Hello %d World"), myValue)
并且在 Localizable.strings
这一行中:
MyCustomKey = "Hello %d World";