If have the following plural ressource in my strings.xml:
<plurals name="item_shop"> <item quantity="zero">No item</item> <item quantity="one">One item</item> <item quantity="other">%d items</item> </plurals>
I'm showing the result to the user using:
textView.setText(getQuantityString(R.plurals.item_shop, quantity, quantity));
It's working well with 1 and above, but if quantity is 0 then I see "0 items". Is "zero" value supported only in Arabic language as the documentation seems to indicate? Or am I missing something?
The plural form of android is androids.
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.
The Android resource method of internationalisation is quite limited. I have had much better success using the standard java.text.MessageFormat
.
Basically, all you have to do is use the standard string resource like this:
<resources> <string name="item_shop">{0,choice,0#No items|1#One item|1<{0} items}</string> </resources>
Then, from the code all you have to do is the following:
String fmt = getResources().getText(R.string.item_shop).toString(); textView.setText(MessageFormat.format(fmt, amount));
You can read more about the format strings in the javadocs for MessageFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With