質問

I have to localize detail-text-label using stringWithFormat with an integer value as shown below.

cell.detailTextLabel.text = 
    [NSString stringWithFormat:@"Remaining: %d", count];
役に立ちましたか?

解決

For example, assuming that "Remaining: %d" = "Remaining: %d is in your English Localizable.strings file and "Remaining: %d" = "Restante: %d is in your Spanish one, the following code will solve your particular problem:

cell.detailTextLabel.text = 
    [NSString stringWithFormat:NSLocalizedString(@"Remaining: %d", @"description for translators"), count];

If you ever need to localize a string with more than one argument, then the above solution is not flexible enough (in some languages you may need to change the order of the placeholders). You can use positional specifiers to add this kind of flexibility to your solution.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top