Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.stringsdict not working in iOS8

Tags:

ios

swift

having some issues using .stringsdict. Code like so:

<?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>groups-selected</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@groups@</string>
        <key>groups</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>one</key>
            <string>%d group selected</string>
            <key>other</key>
            <string>%d groups selected</string>
        </dict>
    </dict>
    <key>friends-online</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@friends@</string>
        <key>friends</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>one</key>
            <string>%d friend online</string>
            <key>other</key>
            <string>%d friends online</string>
        </dict>
    </dict>
    <key>points-usage-message</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>%#@points@</string>
        <key>points</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>d</string>
            <key>one</key>
            <string>%d point will be deducted</string>
            <key>other</key>
            <string>%d points will be deducted</string>
        </dict>
    </dict>
</dict>
</plist>

The localization works find in iOS9+ in the simulator and on the device however for iOS8 it won't work on neither and I'll just get the key name output i.e.: points-usage-message. Any ideas what I might be doing wrong here?

like image 392
KexAri Avatar asked Jan 29 '16 13:01

KexAri


3 Answers

Check http://maniak-dobrii.com/understanding-ios-internationalization/ , specially the part that says:

"A quick gotcha for .stringsdict: don't forget to have (at least empty) .strings file with the same name for each localization you support, otherwise .stringsdict won't be recognized and used."

In my case, I had a localised .stringsdict file and a non localized .strings file. iOS9 was able to show the correct translation, but iOS8 failed miserably

like image 137
gragera Avatar answered Nov 17 '22 03:11

gragera


Actually it occurs to work on iOS 8.4. We're also using .strinsgdict format. So i added this code:

<key>points-usage-message</key>
<dict>
    <key>NSStringLocalizedFormatKey</key>
    <string>%#@points@</string>
    <key>points</key>
    <dict>
        <key>NSStringFormatSpecTypeKey</key>
        <string>NSStringPluralRuleType</string>
        <key>NSStringFormatValueTypeKey</key>
        <string>d</string>
        <key>one</key>
        <string>%d point will be deducted</string>
        <key>other</key>
        <string>%d points will be deducted</string>
    </dict>
</dict>

to our file and it work properly, when i retrieved it with this code:

[NSString localizedStringWithFormat:NSLocalizedString(@"points-usage-message", nil), 42];

or swift:

let localizedFormat = NSLocalizedString("points-usage-message", comment: "")
let pointsInfo = String.localizedStringWithFormat(localizedFormat, 42)

Please try that code and share the results. Also you could additionally try to check .strinsgdict file target membership and localization (should be set to some country).

like image 6
Radosław Cięciwa Avatar answered Nov 17 '22 03:11

Radosław Cięciwa


Try to change

<string>%#@points@</string>
<key>credits</key>

to

<string>%#@points@</string>
<key>points</key>

for you points-usage-message string. Both string and key have to be the same.

like image 1
Maxim Mikheev Avatar answered Nov 17 '22 05:11

Maxim Mikheev