1

I am trying to implement plural rules localisation. i.e., I expect "One file..." when the argument is 1, "2 files..." when the argument is 2 and likewise.

I followed the Apple guidelines. But I always get the results for plural, even for 1 i.e, "1 files...".

I've created a Localizable.stringsdict file with the following content (exactly like the apple guidelines).

<?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>%d messages in your inbox</key>
        <dict>
            <key>NSStringLocalizedFormatKey</key>
            <string>%#@messages@ in your inbox</string>
            <key>messages</key>
            <dict>
                <key>NSStringFormatSpecTypeKey</key>
                <string>NSStringPluralRuleType</string>
                <key>NSStringFormatValueTypeKey</key>
                <string>d</string>
                <key>one</key>
                <string>One message is</string>
                <key>other</key>
                <string>%d messages are</string>
            </dict>
        </dict>
    </dict>
</plist>

This is how I use this key in code

    NSLog(@"%@", [NSString localizedStringWithFormat:NSLocalizedString(@"%d messages in your inbox", @"Message shown for remaining files"), 1]);

What could be the problem?. Here is the sample code I have tried so far.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
  • This answer http://stackoverflow.com/a/20308191/561610 may be useful for you. The only difference that I've noticed is that the number passed as a parameter is of type `long` instead of `integer`. Hope you can find the solution. – Julio Betta Sep 23 '15 at 12:34

2 Answers2

1

While debugging, I've noticed that Localization.stringsdict file is just ignored. When I've recreated it, everything started to work properly. I guess the original file was created with the wrong type: the correct type should be Property List.

I've sent a pull request as you suggested.

Vladimir Kofman
  • 1,983
  • 21
  • 21
0

It is simply the filename Localizable.stringsdict that was followed by a whitespace behind... Remove the whitespace in the filename and everything will work fine. No need to recreate the file.

According to the initial commit that the author gave, you can see that the filename LocalizationTest/en.lproj/Localizable.stringsdict is followed by a whitespace... that's why it is broken. Rename it and everything will go fine.

E_net4
  • 27,810
  • 13
  • 101
  • 139
Ting Yi Shih
  • 792
  • 2
  • 9
  • 19