And*_*sen 4 cocoa localization objective-c internationalization ios
我正在尝试使用新的支持在iOS 7中进行更复杂的复数本地化.我创建了一个.stringsdict文件,根据Foundation发行说明(以及Cocoa WWDC会话中的新功能)中的信息进行格式化.我已经验证.stringsdict正被复制到我的应用程序包中(确实-[NSBundle pathForResource:...]找到它).但是,+[NSString localizedStringWithFormat:]不会返回根据配置字典中的规则格式化的字符串.
码:
- (IBAction)textFieldEditingDidEnd:(UITextField *)sender
{
NSInteger numPeople = [sender.text integerValue];
self.textView.text = [NSString localizedStringWithFormat:
NSLocalizedString(@"%d people are in the room", @"%d people are in the room"), (long)numPeople];
}
Run Code Online (Sandbox Code Playgroud)
Localizable.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>%d people are in the room</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@num_people_in_room@ in the room</string>
<key>num_people_in_room</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>zero</key>
<string>No one is</string>
<key>one</key>
<string>A person is</string>
<key>two</key>
<string>Two people are</string>
<key>other</key>
<string>%d people are</string>
</dict>
</dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
我还在这里上传了一个完整的,非常简单的示例项目:https://www.dropbox.com/s/mfze377g0r1iqde/PluralDemo.zip.您在文本字段中输入一个数字,并使用结果更新标签-localizedStringWithFormat:.
有没有人得到这个工作?我在设置时做错了什么?
stringsdict(复数)适用于OS X Mavericks和iOS 7,并且基于Unicode CLDR(公共区域设置数据存储库).英语仅支持零,一和其他.某些语言支持"Two",例如阿拉伯语,希伯来语,爱尔兰语等.
正如我在下面的回复中提到的(从2014年1月13日开始),仍然需要常规字符串文件,即使它是空的.
你还添加了空字符串文件吗?文档说你必须添加字符串文件,即使它是空的,可能是由于Cocoa内部实现了本地化.