My question is similar to How to add regular string placeholders to a translated plurals .stringdict in swift ios but I am trying to understand if it is possible to pass 2 i
One format is sufficient. You can use multiple placeholders in the NSStringLocalizedFormatKey
entry, and for each placeholder a separate dictionary with the plural rule. Example:
apples_and_pears
NSStringLocalizedFormatKey
%#@num_apples@ : %#@num_pears@
num_apples
NSStringFormatSpecTypeKey
NSStringPluralRuleType
NSStringFormatValueTypeKey
ld
zero
no apple
one
1 apple
other
%ld apples
num_pears
NSStringFormatSpecTypeKey
NSStringPluralRuleType
NSStringFormatValueTypeKey
ld
zero
no pear
one
1 pear
other
%ld pears
Usage:
let apples = 1
let pears = 3
let format = NSLocalizedString("apples_and_pears", comment: "")
let applesAndPears = String.localizedStringWithFormat(format, apples, pears)
print(applesAndPears) // 1 apple : 3 pears
This can be combined with positional parameters: if the format is changed to
NSStringLocalizedFormatKey
%2$#@num_pears@ : %1$#@num_apples@
then the output becomes “3 pears : 1 apple”.