.stringsdict在iOS8中不起作用

前端之家收集整理的这篇文章主要介绍了.stringsdict在iOS8中不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用.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>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>

本地化工作在iOS9中可以在模拟器和设备上找到,但是对于iOS8它既不会工作,我只会获得密钥名称输出,即:points-usage-message.我在这里做错了什么想法?

解决方法

实际上它适用于iOS 8.4.我们也使用.strinsgdict格式.所以我添加了这段代码
<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>

到我们的文件,它正常工作,当我用这段代码检索它:

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

或迅捷:

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

请尝试该代码分享结果.此外,您还可以尝试检查.strinsgdict文件目标成员资格和本地化(应设置为某个国家/地区).

原文链接:https://www.f2er.com/iOS/328829.html

猜你在找的iOS相关文章