How to handle plurals in localisation objective-c iOS

I’m going through this page to see how to handle plurals.

https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html#//apple_ref/doc/uid/10000171i-CH5-SW10

I’ve added an english.stringsdict which contains the following.

<plist version="1.0">
    <dict>
        <key>%d file(s) remaining</key>
        <dict>
            <key>NSStringLocalizedFormatKey</key>
            <string>%#@files@</string>
            <key>files</key>
            <dict>
                <key>NSStringFormatSpecTypeKey</key>
                <string>NSStringPluralRuleType</string>
                <key>NSStringFormatValueTypeKey</key>
                <string>d</string>
                <key>one</key>
                <string>%d file remaining</string>
                <key>other</key>
                <string>%d files remaining</string>
            </dict>
        </dict>
    </dict>
</plist>

I’ve set the localisation property in the file inspector to english
I have a Localizable.strings also set to english which contains the following.

/* Message shown for remaining files */
"%d file(s) remaining" = "%d file(s) remaining";

I’ve set application language in schema to english.

I’m setting label text like this

self.label.text = [NSString localizedStringWithFormat:NSLocalizedString(@"%d file(s) remaining", @"Message shown for remaining files"), count];

What is being displayed is “5 file(s) remaining”

What I want to display is 5 files remaining or 1 file remaining if there is one file.


Source: ios

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.