'Swift Localization: String String interpolation
I am trying to add multilanguage support to my app. I am doing this by replacing all my User visible Strings with localized strings. For strings like "Cancel", this is easy. But I have just as many strings that are interpolated with information. And the hard part is that each language would build the sentence differently.
For example: How would I localize the following String: "Please enter the 4-digit Code sent to you at (user.PhoneNumber)"
In German, I want the string to look like this: "Bitte gebe den 4-Ziffer Code ein, den wir dir an (user.PhoneNumber) gesendet haben"
Or in French: "Entrez le code à 4 chiffres qui vous a été envoyé à (user.PhoneNumber)"
I am trying to find a way to use some kind of variable inside of my localization file like this (I know that this does not work):
Inside my ViewController:
title.text = "Please enter the 4-digit Code sent to you at %phoneNumber%".localized
Inside my Localizable.string
"Please enter the 4-digit Code sent to you at %phoneNumber%" = "Bitte gebe den 4-Ziffer Code ein, den wir dir an %phoneNumber% gesendet haben"
What's the best practice to do this? This must be some common issue people are having. Languages are so different!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
