在iOS 7中使用新的格式字符串说明符配置字典(复数支持) [英] Using new format string specifier configuration dictionary (plurals support) in iOS 7

查看:280
本文介绍了在iOS 7中使用新的格式字符串说明符配置字典(复数支持)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用新的支持在iOS 7中更复杂的本地化的复数。我创建了一个.stringsdict文件,格式化根据基金会发行说明中的​​信息(以及在Cocoa WWDC会话中的新功能) 。我已经验证了.stringsdict被复制到我的应用程序的包(确实 - [NSBundle pathForResource:...] 找到它)。但是, + [NSString localizedStringWithFormat:] 不返回根据配置字典中的规则格式化的字符串。

I'm trying to use the new support for more sophisticated localization of plurals in iOS 7. I've created a .stringsdict file, formatted according to the information in the Foundation release notes (and What's New In Cocoa WWDC session). I've verified that the .stringsdict is being copied into my app's bundle (and indeed -[NSBundle pathForResource:...] finds it). However, +[NSString localizedStringWithFormat:] doesn't return a string formatted according to the rules in the configuration dictionary.

代码:

- (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];
}

Localizable.stringsdict:

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>



我也在这里上传了一个非常简单的示例项目: https://www.dropbox.com/s/mfze377g0r1iqde/PluralDemo.zip 。您在文本字段中输入一个数字,并使用 -localizedStringWithFormat:的结果更新标签。

I've also uploaded a complete, very simple sample project here: https://www.dropbox.com/s/mfze377g0r1iqde/PluralDemo.zip . You enter a number in the text field, and a label is updated with the result of -localizedStringWithFormat:.

有没有人得到这个工作?

Has anyone gotten this to work? Have I done something wrong in setting it up?

推荐答案

stringsdict(plurals)在OS X Mavericks和iOS 7中都有效基于Unicode CLDR(公共区域设置数据存储库)。英语只支持零,一和其他。

stringsdict (plurals) works in both OS X Mavericks and iOS 7 and is based on Unicode CLDR (Common Locale Data Repository). English supports only zero, one, and other. "Two" is supported in some languages, such as Arabic, Hebrew, Irish, etc.

  • Foundation Release Notes for OS X v10.9
  • Unicode CLDR Language Plural Rules

正如我在下面的回复(2014年1月13日)中提到的,仍然需要常规字符串文件,即使它是空的。

As I mentioned in a response below (from Jan 13, 2014), the regular strings file is still required, even if it's empty.


你还添加了一个空的字符串文件?文档说,你必须添加字符串文件,即使它将是空的,可能是由于在Cocoa本地化的内部实现。

did you also add an empty strings file? The documentation says that you must add the strings file even if it's going to be empty, probably due to the internal implementation of localization in Cocoa.

这篇关于在iOS 7中使用新的格式字符串说明符配置字典(复数支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆