Stringsdict File Format
A .stringsdict file is a property list used to define language plural rules.
Localized String Properties
Each key-value pair in the .stringsdict file defines a plural rule for a specific string, as in:
<plist version="1.0"> |
<dict> |
<key>%d file(s) remaining</key> |
<dict> |
… |
</dict> |
<key>%d service hour(s)</key> |
<dict> |
… |
</dict> |
<key>%d award(s)</key> |
<dict> |
… |
</dict> |
</dict> |
</plist> |
You pass the same strings—for example, @”%d file(s) remaining”, @”%d service hour(s)” and @”%d award(s)”—to a NSLocalizedString macro in your code.
Localized Format String Properties
The plural rule determines the format string returned by the NSLocalizedString macro. You supply a format string for each category of numbers the language defines. The value of this dictionary has the following keys:
NSStringLocalizedFormatKeyA format string that contains variables. A variable is preceded by the
%#@characters and followed by the@character, as in:<key>NSStringLocalizedFormatKey</key>
<string>%#@files@</string>
where the variable name is
files. The format string can contain multiple variables, as in%#@files@ (%#@bytes@, %#@minutes@).[variable]A dictionary of key-value pairs specifying the rule to use for
[variable], as in:<key>files</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>%d file remaining</string>
<key>other</key>
<string>%d files remaining</string>
</dict>
For example, if the number is 2, the
@”%d files remaining”format string is returned and the localized string becomes@”2 files remaining”.
Add plural rules for each variable that appears in the NSStringLocalizedFormatKey format string.
Plural Rule Properties
The [variable] dictionary contains the following keys:
NSStringFormatSpecTypeKeySpecifies the type of language rule. The only possible value is
NSStringPluralRuleType, which indicates a language plural rule.NSStringFormatValueTypeKeyA string format specifier for a number, as in
%dfor an integer. For a list of format specifiers, see String Format Specifiers in String Programming Guide.zeroThe format string to use for the number 0.
oneThe format string to use for the number 1.
twoThe format string to use for the number 2.
few,manyFormat strings to use for additional language-dependent categories.
otherThe format string to use for all numbers not covered by the other categories. This key is required.
The meaning of the categories is language-dependent, and not all languages have the same categories.
For example, English only uses the
one, andothercategories to represent plural forms. Arabic has different plural forms for thezero,one,two,few,many, andothercategories. Although Russian also uses themanycategory, the rules for which numbers are in themanycategory are not the same as the Arabic rules.All of the categories are optional except
other.However, your text may be grammatically incorrect if you don’t supply a rule for all the language-specific categories. Conversely, if you provide a rule for a category not used by a language, it is ignored and the
otherformat string is used.Using the
NSStringFormatValueTypeKeyformat specifier in thezero,one,two,few,many, andotherformat strings is optional.For example, the
oneformat string can beOne file remainingwhile theotherformat string can be%d files remainingfor English.Use the format specifier or spell out numbers in the format strings.
If you use a numeric in the format string, as in
1 file remainingfor English, it may not be localized when the user changes the region (for example, if the number set changes). Instead, use the format specifier, as in%d file remaining; otherwise, spell out the number, as inOne file remaining.
For the plural categories and rules for each language, see CLDR Language Plural Rules.
Copyright © 2015 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2015-09-16