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

本小妞迷上赌 提交于 2019-12-03 11:38:21

Android is using the CLDR plurals system, and this is just not how it works (so don't expect this to change).

The system is described here:

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:

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". There are certainly plenty of cases where "two" contains other numbers than just 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.

That's an old bug. There are just a few missing if-clauses in the relevant code section of the PluralRules class.

As the answer in your linked question stated, you are better off by using MessageFormat or something else. 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).

Completely false, see the comments.

Yes, the usage of two is specific to locale. Just because you give it the number 2 does not mean that it will use quantity="two". It will only use that quantity for languages that have special cases for the number 2

From 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). 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. Rely on your translator to know what distinctions their language actually insists upon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!