문제

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