Post marked as solved
Post marked as solved with 6 replies, 3,614 views
Hi.I was trying to do internationalization friendly pluralization in my code.My source string looks like this:NSString *fromString = [NSString localizedStringWithFormat:NSLocalizedString(@"%@ + %d other(s)", @"The from field for the message cell"), senderName, numberOfParticipants];And I added the following to the stringsdict file for the project:<key>%@ + %d other(s)</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@others@</string>
<key>others</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>%@</string>
<key>one</key>
<string>%@ + %d other</string>
<key>other</key>
<string>%@ + %d others</string>
</dict>
</dict>But the only string that was being displayed was from the other category.John Doe + 0 othersJohn Doe + 1 othersJohn Doe + 2 othersAfter some trial and error my source string ended up like this:NSString *fromString = [NSString localizedStringWithFormat:NSLocalizedString(@"%2$@ + %1$d other(s)", @"The from field for the message cell"), numberOfParticipants, senderName];My stringsdict I formatted it like this:<key>%2$@ + %1$d other(s)</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@others@</string>
<key>others</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>%2$@</string>
<key>one</key>
<string>%2$@ + %1$d other</string>
<key>other</key>
<string>%2$@ + %1$d others</string>
</dict>
</dict>This gave me:John DoeJohn Doe + 1 otherJohn Doe + 2 othersI'm really skeptical of calling it a solution. It seems like you should be able to specify the position of the parameter to read for the count of items, but I can't find any example or documentation which can enlighten me. The internaionalization guide only deals with simple strings with zero or one replacement parameters, the documentation for localizedStringWithFormat doesn't mention any special handling for pluralization.What am I doing wrong?