Your localized string itself must be a format pattern:
"ValueAndStringFMT" = "Value %1$d and string %2$@";
And in your code:
textLabel.text = [NSString
stringWithFormat:NSLocalizedString(@"ValueAndStringFMT"),
value, str
];
Why %1$d
and not just %d
? So you can change the order. E.g. in some language you may like to have the order swapped:
"ValueAndStringFMT" = "Cadena %2$@ y valor %1$d";
Of course, that is somewhat dangerous as if someone uses more placeholders than your string call offers or uses the wrong types, your app may crash. If you want to be safe, you do a search an replace instead:
"ValueAndStringFMT" = "Value [[VALUE]] and string [[STRING]]";
And in your code:
NSString * string = NSLocalizedString(@"ValueAndStringFMT");
string = [string stringByReplacingOccurrencesOfString:@"[[VALUE]]"
withString:@(value).stringValue
];
string = [string stringByReplacingOccurrencesOfString:@"[[STRING]]"
withString:str
];
textLabel.text = string;
That way the worst case scenario is that a placeholder is not expanded, meaning the placeholder is visibly printed on screen but at least your app won't crash because someone messed up the localization strings file.
If you need to localize one of the format variables, then you need to do that first in an own step:
NSString * str = NSLocalizedString(@"hello");