Search code examples
localizationnsstringnsnumberformatternslocalizedstringplural

Using ".stringsdict" file with 'localizedStringWithFormat' --> Are NUMERALS localized for you?


I am trying to produce the following localized string:

"In ___ day(s)" --> (ex: In 5 days)

To accomplish this, I've gone down the .stringsdict route:

<key>In %d Days</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@Days@</string>
        <key>Days</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>zero</key>
            <string>Today</string>
            <key>one</key>
            <string>In %d Day</string>
            <key>other</key>
            <string>In %d Days</string>
        </dict>
    </dict>

I then use the following, to obtain a localized string:

NSInteger days = ...;
localizedDueDateString = [NSString localizedStringWithFormat:NSLocalizedString(@"In %d Days", @"Indicates days"),ABS(days)];

This correctly outputs a string that accounts for plurality. For example:

In 1 day
In 4 days

I am wondering if the "1" and the "4" here will be localized correct. Other languages, like Arabic for example, have different symbols for their numerals. I would expect the above string to use the symbol "٤" instead of "4", for arabic.

I know this can be accomplished using an NSNumberFormatter, but how can I accomplish numeral localization while ALSO respecting plurality visa vi a .stringsdict file?


Solution

  • YES

    Numerals do appear to be correctly swapped when using a .stringsdict file in coordination with "localizedStringWithFormat" method!

    I switched my iPad language to Arabic, and the output for

    In 1 day
    

    was...

    ١ day In 
    

    I don't have an arabic localization done yet, so "In" and "day" are english, but the numeral appears to be correctly localized. No need for NSNumberFormatter