Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using new format string specifier configuration dictionary (plurals support) in iOS 7

I'm trying to use the new support for more sophisticated localization of plurals in iOS 7. I've created a .stringsdict file, formatted according to the information in the Foundation release notes (and What's New In Cocoa WWDC session). I've verified that the .stringsdict is being copied into my app's bundle (and indeed -[NSBundle pathForResource:...] finds it). However, +[NSString localizedStringWithFormat:] doesn't return a string formatted according to the rules in the configuration dictionary.

Code:

- (IBAction)textFieldEditingDidEnd:(UITextField *)sender
{
    NSInteger numPeople = [sender.text integerValue];
    self.textView.text = [NSString localizedStringWithFormat:
                          NSLocalizedString(@"%d people are in the room", @"%d people are in the room"), (long)numPeople];
}

Localizable.stringsdict:

<?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 people are in the room</key>
     <dict>
          <key>NSStringLocalizedFormatKey</key>
          <string>%#@num_people_in_room@ in the room</string>
          <key>num_people_in_room</key>
          <dict>
               <key>NSStringFormatSpecTypeKey</key>
               <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
               <key>zero</key>
               <string>No one is</string>
                     <key>one</key>
                     <string>A person is</string>
               <key>two</key>
               <string>Two people are</string>
                     <key>other</key>
                     <string>%d people are</string>
          </dict>
     </dict>
</dict>
</plist>

I've also uploaded a complete, very simple sample project here: https://www.dropbox.com/s/mfze377g0r1iqde/PluralDemo.zip . You enter a number in the text field, and a label is updated with the result of -localizedStringWithFormat:.

Has anyone gotten this to work? Have I done something wrong in setting it up?

like image 931
Andrew Madsen Avatar asked Dec 16 '22 05:12

Andrew Madsen


1 Answers

The problem here is that you are missing Localizable.strings file.

It is required even if it is empty.

Tried it with your project and adding the file made the project work just fine.

like image 199
user3774312 Avatar answered Apr 26 '23 23:04

user3774312