Localizable.stringsdict: getting English to use the "two" key

196 views Asked by At

I have an object with an executionCount property and I'd like to display to the user how many times the object will execute. For example, in English:

X will execute once
X will execute twice
X will execute %d times

I have created a Localizable.stringsdict and it works correctly when executionCount is 1 ("one") or 3+ ("other"). But not for 2.

I understand that in English there are only two grammatical numbers (singular and plural) but isn't there any way to force the use of "two" for English? And if not, why shouldn't it be so?

Apple's documentation links to this web page where it says the following:

cardinal    one      1
            other    0, 2~16, 100, 1000, 10000, 100000, 1000000, …
ordinal     one      1, 21, 31, 41, 51, 61, 71, 81, 101, 1001, …
            two      2, 22, 32, 42, 52, 62, 72, 82, 102, 1002, …
            few      3, 23, 33, 43, 53, 63, 73, 83, 103, 1003, …
            other    0, 4~18, 100, 1000, 10000, 100000, 1000000, …

Can't localization be used for the "ordinal" case?

Here's my code:

let willExecute = NSLocalizedString("willExecute", comment: "...")
String.localizedStringWithFormat(willExecute, object.executionCount)

and my Localizable.stringsdict

<dict>
    <key>willExecute</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@times@</string>
        <key>times</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>one</key>
            <string> will execute once</string>
            <key>two</key>
            <string> will execute twice</string>
            <key>other</key>
            <string> will execute %d times</string>
        </dict>
    </dict>
</dict>
0

There are 0 answers