I am using this piece of code to localize dates to Strings in Swift:
if elapsedTime > 3600 {
let hourString = NSLocalizedString("hour ago", tableName: "v1.0.0", bundle: Bundle.main, value: "hour ago", comment: "")
let hoursString = NSLocalizedString("hours ago", tableName: "v1.0.0", bundle: Bundle.main, value: "hours ago", comment: "")
let hours = Int(elapsedTime/3600)
return "\(hours) " + (hours > 1 ? hoursString : hourString)
}
where the elapsedTime is a value in seconds. Result for english localization is
6 hours ago
for example. I need to modify this to add language specific localization, for example in french it should be not in a format of [N] hours ago
but il ya [N] heurs
. Is there a way to automate it, avoiding adding specific prefix for different languages at which it used?
Thanks in advance!