简体   繁体   中英

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.

You cannot have the same key in the Localizable.strings as in the Localizable.stringsdict. The system first looks into Localizable.strings and if the key is not found, he looks into Localizable.stringsdict.

Solution: Just remove

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

from Localizable.strings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM