2

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>
nyg
  • 2,380
  • 3
  • 25
  • 40
  • @MartinR It is... I did not find it during my search (it doesn't have the best of titles). I will delete my question. – nyg Sep 07 '17 at 13:21
  • 1
    @nyg You can let yours and mark it as duplicate yourself. If you think that yours is more describing the issue, then other people with the same issue will more easily find yours, and the the duplicate question ;) – Larme Sep 07 '17 at 14:26
  • @Larme That is a better alternative, I felt bad about deleting my own question :). – nyg Sep 07 '17 at 14:29

0 Answers0