Stringsdict File Format
A .stringsdict
file is a property list used to define language plural rules.
Avoid using a .stringsdict
file with a string that does not include a number, because a language might define generic singular and plural forms in ways that don’t work well with the one
and other
categories.
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:
NSStringLocalizedFormatKey
A 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:
NSStringFormatSpecTypeKey
Specifies the type of language rule. The only possible value is
NSStringPluralRuleType
, which indicates a language plural rule.NSStringFormatValueTypeKey
A string format specifier for a number, as in
%d
for an integer. For a list of format specifiers, see String Format Specifiers in String Programming Guide.zero
The format string to use for the number 0.
one
The format string to use for additional language-dependent categories.
two
The format string to use for additional language-dependent categories.
few
,many
Format strings to use for additional language-dependent categories.
other
The 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
andother
categories to represent plural forms. Arabic has different plural forms for thezero
,one
,two
,few
,many
, andother
categories. Although Russian also uses themany
category, the rules for which numbers are in themany
category 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
other
format string is used.Using the
NSStringFormatValueTypeKey
format specifier in thezero
,one
,two
,few
,many
, andother
format strings is optional.For example, the
one
format string can beOne file remaining
while theother
format string can be%d files remaining
for 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 remaining
for 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