1

I have the well known problem of "number of selected out of total": if I work in the xib I use DisplayPattern Value1 and Value2 where the pattern is "#{value1}@ selected out of %{value2}@" and it works. Now I'd want to localize my app: so I inserted in the applicationDidFinishLaunching method the code

NSString *formatString = NSLocalizedString(@"%{value1}@ selected out of %{value2}@",@"");
[self.labelNum bind:@"displayPatternValue1" toObject:self.arrayCtrl withKeyPath:@"selection.@count" options:@{NSDisplayPatternBindingOption: formatString}];
[self.labelNum bind:@"displayPatternValue2" toObject:self.arrayCtrl withKeyPath:@"arrangedObjects.@count" options:@{NSDisplayPatternBindingOption: formatString}];

The self.arrayCtrl is the array controller of the objects. Now it is still working. But now I want to use a .stringsdict to account for the various cases. My plist is:

<?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>%{value1}@ selected out of %{value2}@</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@selected_objects@</string>
        <key>selected_objects</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>u</string>
            <key>zero</key>
            <string>None selected out of %#@total_objects@</string>
            <key>one</key>
            <string>One object selected out of %#@total_objects@</string>
            <key>other</key>
            <string>%u selected out of %#@total_objects@</string>
        </dict>
        <key>total_objects</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>u</string>
            <key>zero</key>
            <string>none</string>
            <key>one</key>
            <string>one object</string>
            <key>other</key>
            <string>%u</string>
        </dict>
    </dict>
</dict>
</plist>

I also tried to change the key in the NSLocalizedString call and the corresponding string in the .stringsdict, but the result is always the same: the field text presents the first value as a string: %#@selected_objects@, in this case. I also tried to broke down the problem to a simple binding with a pattern, but the result doesn't change. Does that mean that it is not possible to use plural rules with binding? Or there is something I miss? I googled around a lot but I didn't find a similar situation.

max.me
  • 105
  • 7
  • I don't think the binding will localize the string, it replaces `%{value1}@` by the value of `selection.@count`, every time `selection` or `selection.@count` changes. – Willeke Aug 17 '18 at 10:22
  • @Willeke Yes, I suspect... The stringsdict is doing something, as the result is the string of the FormatKey, but all stop there... – max.me Aug 18 '18 at 15:35

0 Answers0