Search code examples
androidtranslationplural

Quantity "two" not working in Android Strings-Resources Plural


Android allows translators to define Plurals. The following example works for me with locale '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. Is the usage of two dependent upon the locale? So does Android only take the two version if the locale explicitly specifies that there should be a two version?

The SO Question Android plurals treatment of “zero” spots the same mistake when using zero in English which is also not supported. There are no solutions in this question except to avoid Android plurals which I want to avoid.


Solution

  • 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.