How to create a formatted localized string?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-05-15T19:53:38Z Indexed on 2010/05/15 20:04 UTC
Read the original article Hit count: 252

Filed under:
|

I have a localized string which needs to take a few variables. However, in localization it is important that the order of the variables can change from language to language.

So this is not a good idea:

NSString *text = NSLocalizedString(@"My birthday is at %@ %@ in %@", nil);

In some languages some words come before others, while in others it's reverse. I lack of an good example at the moment.

How would I provide NAMED variables in a formatted string? Is there any way to do it without some heavy self-made string replacements? Even some numbered variables like {%@1}, {%@2}, and so on would be sufficient... is there a solution?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about string-formatting