I have a localized NSString that is something like “You win. It was Chuck Norris.”. The French translation of this is “Gagne. il s’agissait bien de Chuck Norris”. But when the name starts with a vowel it should say “Gagné. il s’agissait bien d’Alfred Hitchcock”.
Does NSString offer support for these situations or do I need to manually translate each possibility?
If you’re trying to do localization using tools like
NSLocalizedString(), variations like this are going to occur in a lot of languages (especially those with grammatical genders) and are a lot of trouble to deal with. There’s no inbuilt change-strings-if-starting-with-a-vowel method, but something like this would be necessary (pseudo-code):Why did I give you pseudo-code instead of real code? Because this is the wrong way to do this work. It’s messy, it’s ugly, and there are a lot of edge cases. For instance, the letter “H” in French can be “aspirated” or “non-aspirated”, and one takes “l’/d'” while the other takes “le/la/de” (compare “l’hôtel” and “le hockey”.) The distinction is arbitrary and cannot be determined solely by examining the spelling of the word.
Rather than attempting to match your format string to the name, try to change the format string to be neutral. Instead of
"Il s'agissait bien d'%@.", try"Le nom? C'est %@!"so that the gender and spelling of the name do not affect the localization. Different languages will have different options here.