简体   繁体   English

.stringsdict 在 iOS8 中不起作用

[英].stringsdict not working in iOS8

having some issues using .stringsdict.使用 .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 ie: points-usage-message .本地化可以在模拟器和设备中的 iOS9+ 中找到,但是对于 iOS8,它在两者上都不起作用,我只会得到键名输出,即: points-usage-message Any ideas what I might be doing wrong here?任何想法我在这里可能做错了什么?

Check http://maniak-dobrii.com/understanding-ios-internationalization/ , specially the part that says:检查http://maniak-dobrii.com/understanding-ios-internationalization/ ,特别是说:

"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." “.stringsdict 的一个快速问题:不要忘记为您支持的每个本地化提供(至少是空的).strings 文件,否则 .stringsdict 将不会被识别和使用。”

In my case, I had a localised .stringsdict file and a non localized .strings file.就我而言,我有一个本地化的 .stringsdict 文件和一个非本地化的 .strings 文件。 iOS9 was able to show the correct translation, but iOS8 failed miserably iOS9 能够显示正确的翻译,但 iOS8 却惨遭失败

Actually it occurs to work on iOS 8.4.实际上它适用于 iOS 8.4。 We're also using .strinsgdict format.我们也在使用.strinsgdict格式。 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).此外,您还可以尝试检查.strinsgdict文件目标成员资格和本地化(应设置为某个国家/地区)。

Try to change尝试改变

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

to

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

for you points-usage-message string.为您points-usage-message字符串。 Both string and key have to be the same. stringkey都必须相同。

Also to note.还要注意。 The .stringsdict and the .strings file have to be located at the root of the Project. .stringsdict 和 .strings 文件必须位于项目的根目录下。 Otherwise they are not found.否则它们不会被发现。

我在 Xcode 9 上遇到了类似的问题,我不得不删除我的 .stringsdict 文件,重新创建它,将其放入根项目文件夹,然后将其添加到目标中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM