简体   繁体   English

数量“两”在Android Strings-Resources Plural中不起作用

[英]Quantity “two” not working in Android Strings-Resources Plural

Android allows translators to define Plurals . Android允许翻译人员定义Plurals The following example works for me with locale 'en': 以下示例适用于我的语言环境'en':

<plurals name="numberOfSongsAvailable">
    <item quantity="one">One song found.</item>
    <item quantity="other">%d songs found.</item>
</plurals>

But adding a special value for two does not work, still the other version is taken. 但是为two添加特殊值不起作用,仍然采用other版本。 Is the usage of two dependent upon the locale? two用法是否依赖于语言环境? So does Android only take the two version if the locale explicitly specifies that there should be a two version? 因此,没有安卓只能坐two版本,如果语言环境明确指定,应该有一个two版本?

The SO Question Android plurals treatment of “zero” spots the same mistake when using zero in English which is also not supported. SO问题Android复数处理“零”在使用英语zero也发现同样的错误,这也是不支持的。 There are no solutions in this question except to avoid Android plurals which I want to avoid. 除了避免我想要避免的Android复数之外,这个问题没有解决方案。

Android is using the CLDR plurals system, and this is just not how it works (so don't expect this to change). Android正在使用CLDR复数系统,这不是它的工作原理(所以不要指望这会改变)。

The system is described here: 该系统在这里描述:

http://cldr.unicode.org/index/cldr-spec/plural-rules http://cldr.unicode.org/index/cldr-spec/plural-rules

In short, it's important to understand that "one" does not mean the number 1. Instead these keywords are categories, and the specific numbers n that belong to each category are defined by rules in the CLDR database: 简而言之,理解“一个”并不意味着数字1是很重要的。相反,这些关键字是类别,属于每个类别的特定数字n由CLDR数据库中的规则定义:

http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html

While there appears to be no language which uses "zero" for anything other than 0, there are languages which assign 0 to "one". 虽然似乎没有语言对0以外的任何东西使用“零”,但有些语言将0分配给“1”。 There are certainly plenty of cases where "two" contains other numbers than just 2. 肯定有很多情况下“两个”包含其他数字而不仅仅是2。

If Android where to allow you to do what you intended, your applications could not be properly translated into any number of languages with more complex plural rules. 如果Android允许您执行您的预期操作,则无法将您的应用程序正确地翻译成具有更复杂复数规则的任意数量的语言。

That's an old bug . 那是一个 老bug There are just a few missing if-clauses in the relevant code section of the PluralRules class . PluralRules类相关代码部分中只有一些缺少if子句。

\n

As the answer in your linked question stated, you are better off by using MessageFormat or something else. 正如您在链接问题中的答案所述,使用 MessageFormat或其他方法会更好。 The bug has been reported in may 2010, I wouldn't expect that beeing fixed in the near future (and you still have a faulty version on old version devices in this case) . 该错误已于2010年5月报告,我不希望在不久的将来修复该问题 (在这种情况下,旧版设备上仍然存在故障版本)

Completely false, see the comments. 完全错误,请参阅评论。

Yes, the usage of two is specific to locale. 是的,使用2是特定于区域设置。 Just because you give it the number 2 does not mean that it will use quantity="two". 仅仅因为你给它2号并不意味着它将使用quantity =“two”。 It will only use that quantity for languages that have special cases for the number 2 它仅对具有2号特殊情况的语言使用该数量

From http://developer.android.com/guide/topics/resources/string-resource.html#Plurals : 来自http://developer.android.com/guide/topics/resources/string-resource.html#Plurals

Note that the selection is made based on grammatical necessity. 请注意,选择是基于语法上的必要性。 A string for zero in English will be ignored even if the quantity is 0, because 0 isn't grammatically different from 2, or any other number except 1 ("zero books", "one book", "two books", and so on). 即使数量为0,也会忽略英语为零的字符串,因为0在语法上与2不同,或者除1以外的任何其他数字(“零书”,“一本书”,“两本书”等等)上)。 Don't be misled either by the fact that, say, two sounds like it could only apply to the quantity 2: a language may require that 2, 12, 102 (and so on) are all treated like one another but differently to other quantities. 不要因为两个声音只能应用于数量2这一事实而被误导:一种语言可能要求2,12,102(等等)都被视为彼此相似但与其他不同数量。 Rely on your translator to know what distinctions their language actually insists upon. 依靠你的翻译来了解他们的语言实际上坚持的区别。

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

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