Plural definition is ignored for zero quantity

后端 未结 3 714
慢半拍i
慢半拍i 2020-12-06 04:02

I use plurals to compile a quantity string for an Android application. I follow exactly what one can find in the tutorials:



        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 04:41

    According to the documentation :

    The selection of which string to use is made solely based on grammatical necessity. In English, a string for zero 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).

    If you still want to use a custom string for zero, you can load a different string when the quantity is zero :

    if (commentsCount == 0)
        str = res.getString(R.string.number_of_comments_zero);
    else
        str = res.getQuantityString(R.plurals.number_of_comments, commentsCount, commentsCount);
    

提交回复
热议问题