简体   繁体   中英

Swift 3 Plural always go to "other"

My Localizable.stringsdict are as follows. And the locale is ENGLISH,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>numberOfLike</key>
        <dict>
            <key>NSStringLocalizedFormatKey</key>
            <string>%#@value@</string>
            <key>value</key>
            <dict>
                <key>NSStringFormatSpecTypeKey</key>
                <string>NSStringPluralRuleType</string>
                <key>NSStringFormatValueTypeKey</key>
                <string>d</string>
                <key>one</key>
                <string>%d LIKE</string>
                <key>other</key>
                <string>%d LIKES</string>
            </dict>
        </dict>
    </dict>
</plist>

but the output is always the "other"

The code of getting the strings is

let format = NSLocalizedString("numberOfLike", comment: "")
let message = String.localizedStringWithFormat(format, 1)

which is "1 LIKES". Any Help?

Sorry Guys, the code works. What goes wrong is I am using in app localization, and the plugin has problems when the device locale is different with the in app locale.

For Localisation of Plural, create a Localizable.stringsdict file like this,

在此处输入图片说明

let title = String.localizedStringWithFormat(NSLocalizedString("CANCEL_SELECTED_TICKETS_TITLE", comment: ""), 2)

在此处输入图片说明

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