2

プロパティを持つオブジェクトがありexecutionCount、オブジェクトが実行される回数をユーザーに表示したいと考えています。たとえば、英語では次のようになります。

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

executionCountLocalizable.stringsdict を作成しましたが、1 (「1 つ」) または 3+ (「その他」) の場合に正しく機能します。しかし、2のためではありません。

英語には文法上の数が 2 つ (単数と複数) しかないことは理解していますが、英語で「2」を強制的に使用する方法はありませんか? もしそうでなければ、なぜそうすべきではないのですか?

Apple のドキュメントは、次のように記載されているこのWeb ページにリンクしています。

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, …

「序数」の場合にローカリゼーションを使用できませんか?

これが私のコードです:

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

と私の 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>
4

0 に答える 0