问题描述
在一个Android应用中,我具有以下字符串资源:
In an android app, I have the following string resources:
<plurals name="test">
<item quantity="zero">"I have 0 item"</item>
<item quantity="one">"I have 1 item"</item>
<item quantity="other">"I have several items"</item>
</plurals>
以及以下代码行:
String text = getResources().getQuantityString(R.plurals.test, 0)
我希望返回
但是它实际上会返回
为什么?
推荐答案
在某些平台和电话上,数量字符串被破坏为和此讨论应复数和使用数量字符串".指出.这取决于您无法控制的许多因素(例如手机上的本地化).
Quantity Strings are broken on some Plattforms and phones as the issue Tracker and this discussion "Should Plurals and Quantity Strings be used" points out. It depends on many factors which you cannot control (i.e. localization on the phone).
一种解决方案可以是采用类似于该库的外部库,该库具有相同的功能
One solution can be to take an external library like this one, which mimes the same functionallity.
另一种解决方案在android中的复数形式文档中提出.避免使用它,而使用数量中立"的表述,例如"Books:1"
Another solution is stated in the documentation of plurals in android. Avoid using it and use "quantity-neutral" formulations like "Books: 1"
这篇关于getQuantityString返回值为0的错误字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!