我有一个带有executionCount
属性的对象,我想向用户显示该对象将执行多少次。例如,在英语中:
X will execute once
X will execute twice
X will execute %d times
我创建了一个 Localizable.stringsdict ,它在executionCount
1(“one”)或 3+(“other”)时正常工作。但不是2。
我知道在英语中只有两个语法数字(单数和复数),但是没有任何方法可以强制使用“两个”来表示英语吗?如果不是,为什么不应该这样呢?
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>