Please note
I am not asking about NSLocalizedString()
the macro. I am asking about the NSString
class function + (instancetype)localizedStringWithFormat:(NSString *)format, ...
.
These are two separate things.
Question
I'm trying to use the NSString
class method localizedStringWithFormat
but I just can't work out how I'm supposed to use it.
Whatever I try I don't seem to get the words to appear in the translation file using Xcode 6 export for localization
. I've tried the top two variations here but nothing.
The example in the docs shows...
NSString *myString = [NSString localizedStringWithFormat:@"%@: %f", @"Cost", 1234.56];
Does this mean I have to separate the translated words from the numbers? i.e. could I not just use...
NSString *myString = [NSString localizedStringWithFormat:@"Cost: %f", 1234.56];
If I can use this then what would the translated phrase be and what would the translation be?
If not then why use this at all? Why not just use...
NSString *myString = [NSString stringWithFormat:@"%@: %f", NSLocalizedString(@"Cost"), 1234.56];
What is the difference with this last one?
Either way, can someone show me how to get the actual words translated in this please.
Update
OK, at the moment I'm using a stupid work around that just seems to be misusing everything lol.
If I do...
NSString *myString = [NSString stringWithFormat:@"%@: %f", NSLocalizedString(@"Cost"), 1234.56];
Then it translated the word "Cost" but doesn't use the correct locale for the numbers.
If I use...
NSString *myString = [NSString localizedStringWithFormat:@"%@: %f", @"Cost", 1234.56];
// or
NSString *myString = [NSString localizedStringWithFormat:@"Cost: %f", 1234.56];
Then Xcode "Export for localization" just ignores it completely and nothing about "Cost" is added to the translation file at all so nothing gets translated.
So, I've resorted to using...
[NSString localizedStringWithFormat:@"%@: %f", NSLocalizedString(@"Cost", @"Cost context stuff..."), 1234.56];
This adds "Cost" to the translation file and converts the number to the correct locale but seems like I'm using a lot of redundant stuff here.