Pour faciliter localisant plus facile dans une application très faible de la mienne, j'ai cette méthode d'extension de chaîne:NSLocalizedString avec spécificateurs à Swift donne des ordures
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)
}
}
Ma localisation allemande de Localizable.strings contient cette paire clé/valeur : "WeeksFuture" = "In %d Wochen";
Faire ceci:
for _ in 0..<5 {
let localized = "WeeksFuture".localized(with: 3)
print(localized)
}
tout en ayant Xcode mis à déboguer l'application en allemand (althou gh cela se produit dans toutes les autres langues aussi) imprime ce à la fenêtre de sortie:
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
De toute évidence, cela est faux. Pourquoi ai-je d'abord obtenir la sortie correcte de "Int: 3", puis une chaîne avec un numéro de poubelle apparemment aléatoire?
connexes: [localizeWithFormat et arguments variadique à Swift] (https://stackoverflow.com/questions/27914053/localizewithformat-and-variadic-arguments-in -swift) et [Comment utiliser correctement VarArgs pour localiser les chaînes?] (https://stackoverflow.com/questions/42457503/how-to-properly-use-varargs-for-localizing-strings). –