I'm writing an app in swift that is being localized and I have a question around formatting integers.
Here is a simplified version of my Localizable.stringsdict file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>RecordsFound</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@value@</string>
<key>value</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>$d record found</string>
<key>other</key>
<string>$d records found</string>
</dict>
</dict>
</plist>
Making this call:
String(format: NSLocalizedString("RecordsFound", comment: ""), 1)
returns "1 record found" (singular) and making this call:
String(format: NSLocalizedString("RecordsFound", comment: ""), 2)
returns "2 records found" (plural).
All good so far. However making this call:
String(format: NSLocalizedString("RecordsFound", comment: ""), 15387)
returns "15387 records found". I'd like it to return "15,387 records found" (with the thousand separator). My Language & Region settings are set to use thousand separators but it doesn't seem to pick this up.
I could use NumberFormatter but of course that returns a string which breaks the pluralization rules. I could also pass 2 parameters (the integer itself and a string representation of the integer) but that gets messy especially when there are already multiple integers being passed (some of my strings contain multiple integers and therefore multiple pluralization rules - one for each integer).
Is it possible to add formatting rules to integers in Localizable.stringsdict? If not what's the recommended method of doing this?