mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.5k stars 763 forks source link

Complex plural string in stringsdict doesn't work #220

Closed tomquist closed 8 years ago

tomquist commented 8 years ago

The following .stringsdict file fails with a warning

Skipping string documentList.info.remaining in 'Localizable' (Base), not all format specifiers are consecutive

<?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>documentList.info.remaining</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%1$#@days@</string>
        <key>days</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>ld</string>
            <key>zero</key>
            <string>%2$#@hours@ remaining</string>
            <key>one</key>
            <string>One day remaining</string>
            <key>other</key>
            <string>%ld days remaining</string>
        </dict>
        <key>hours</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>ld</string>
            <key>zero</key>
            <string>%3$#@minutes@</string>
            <key>one</key>
            <string>One hour</string>
            <key>other</key>
            <string>%ld hours</string>
        </dict>
        <key>minutes</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>ld</string>
            <key>zero</key>
            <string>%4$#@seconds@</string>
            <key>one</key>
            <string>One minute</string>
            <key>other</key>
            <string>%ld minutens</string>
        </dict>
        <key>seconds</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>ld</string>
            <key>one</key>
            <string>%ld second</string>
            <key>other</key>
            <string>%ld seconds</string>
        </dict>
    </dict>
</dict>
</plist>
tomlokhorst commented 8 years ago

Does this work in all permutations if your using it without R.swift?

On 20 May 2016, at 17:53, tomquist notifications@github.com wrote:

The following .stringsdict file fails with a warning

Skipping string documentList.info.remaining in 'Localizable' (Base), not all format specifiers are consecutive

<?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">

documentList.info.remaining NSStringLocalizedFormatKey %1$#@days@ days NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey ld zero %2$#@hours@ remaining one One day remaining other %ld days remaining hours NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey ld zero %3$#@minutes@ one One hour other %ld hours minutes NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey ld zero %4$#@seconds@ one One minute other %ld minutens seconds NSStringFormatSpecTypeKey NSStringPluralRuleType NSStringFormatValueTypeKey ld one %ld second other %ld seconds

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub

tomlokhorst commented 8 years ago

To elaborate: R.swift doesn't allow this because String(format:) doesn't work with non-consecutive format specifiers in a stringsdict.

Using this example, the following expression:

String(format: NSLocalizedString("documentList.info.remaining", comment: ""), 0, 0, 1, 0)

Results in: 0 seconds remaining instead of: One minute.

I think the stringsdict format is not intended to be used in such a way.