iOS localization: plurals and NSNumberFormatter

cocoa-touch, ios, objective-c

Solution

After some research I found, that I can separate thousands in number without NSNumberFormatter, just using localizedStringWithFormat. And it also gives me the possibility to use plural rules.

[NSString localizedStringWithFormat:NSLocalizedString(@"%@ Workouts!", @"n Workout(s)"), value]

Localizable.stringsdict

...
<key>%@ Workouts</key>
<dict>
    <key>NSStringLocalizedFormatKey</key>
    <string>%#@Workouts@</string>
    <key>Workouts</key>
    <dict>
        <key>NSStringFormatSpecTypeKey</key>
        <string>NSStringPluralRuleType</string>
        <key>NSStringFormatValueTypeKey</key>
        <string>@</string>
        <key>one</key>
        <string>%@ Workout!</string>
        <key>other</key>
        <string>%@ Workouts!</string>
    </dict>
</dict>
....

Problem

Is there a possibility to use NSNumberFormatter for NSNumber formatting together with plural rules in stringsdict? I need to have the next with formatted numbers (separate thousands). If I format the number using NSNumberFormatter - I receive NSString and I can't use plural rules anymore, because iOS can't understand whether phrase is for single or plural noun from NSString. "1 Workout" for single "1,732,123 Workouts" for plural ``` NSNumberFormatter* numberFormatter = ...; [NSString stringWithFormat:NSLocalizedString(@"%@ Workouts!", @"n Workout(s)"), [numberFormatter stringFromNumber:value]] ```

Original source

Related problems