To facilitate easier localizing in a very small app of mine, I have this String extension method:
extension String {
func localized(with values: Any...) -> String {
// debug values
for v in values {
print("\(type(of: v)): \(v)")
}
return String.localizedStringWithFormat(NSLocalizedString(self, comment: ""), values)
}
}
My German localization of Localizable.strings contains this key/value pair:
"WeeksFuture" = "In %d Wochen";
Doing this:
for _ in 0..<5 {
let localized = "WeeksFuture".localized(with: 3)
print(localized)
}
while having Xcode set to debug the app in German (although this happens in every other language too) prints this to the output window:
Int: 3
In 151.456 Wochen
Int: 3
In 186.912 Wochen
Int: 3
In 186.880 Wochen
Int: 3
In 187.264 Wochen
Int: 3
In 187.488 Wochen
Obviously, this is all wrong. Why do I first get the correct output of "Int: 3", and then a string with a seemingly random garbage number?