使用.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文件目标成员资格和本地化(应设置为某个国家/地区).