Fixed
Status Update
Comments
tn...@google.com <tn...@google.com> #2
For plurals, the actual string chosen depends on the value being passed into the getQuantityString() call. It's true that here, when you've hardcoded it to 1, we could do better and actually perform a plurals lookup to determine the right string to show -- but I suspect that in 99% of cases, the value passed to quantity string is not a fixed number - it's a variable or some other dynamically computed string, so it's unlikely that adding special cases for the case where the variable is a fixed number is going to be useful in a lot scenarios.
de...@gmail.com <de...@gmail.com> #3
It's not the hardcoded String and int values that are causing the error. It still occurs when the preview is resolved with variable names.
I've modified the test code above to demonstrate this:
final boolean isCyclopse = Math.random() > 0.5;
final String name = isCyclopse ? "Cyclopse" : "Bear";
final int quantity = isCyclopse ? 1 : 2;
final String message = getResources().getQuantityString(R.plurals.test_plural, quantity, name, quantity);
Expected Code Folding Preview: "{name} have {quantity} eye"
Observed Code Folding Preview: "{quantity} have {name} eye"
I've modified the test code above to demonstrate this:
final boolean isCyclopse = Math.random() > 0.5;
final String name = isCyclopse ? "Cyclopse" : "Bear";
final int quantity = isCyclopse ? 1 : 2;
final String message = getResources().getQuantityString(R.plurals.test_plural, quantity, name, quantity);
Expected Code Folding Preview: "{name} have {quantity} eye"
Observed Code Folding Preview: "{quantity} have {name} eye"
nd...@gmail.com <nd...@gmail.com> #4
I just observed this issue as well. It seems to be the case that the assumed signature of getQuantityString() is
getQuantityString(int id, Object... formatArgs) // same as getString()
where in fact it is
getQuantityString(int id, int quantity, Object... formatArgs)
Also note the explanation in this resource:http://developer.android.com/guide/topics/resources/string-resource.html
"When using the getQuantityString() method, you need to pass the count twice if your string includes string formatting with a number. For example, for the string %d songs found, the first count parameter selects the appropriate plural string and the second count parameter is inserted into the %d placeholder."
getQuantityString(int id, Object... formatArgs) // same as getString()
where in fact it is
getQuantityString(int id, int quantity, Object... formatArgs)
Also note the explanation in this resource:
"When using the getQuantityString() method, you need to pass the count twice if your string includes string formatting with a number. For example, for the string %d songs found, the first count parameter selects the appropriate plural string and the second count parameter is inserted into the %d placeholder."
pa...@google.com <pa...@google.com> #5
Still reproduces. Taking a look.
pa...@google.com <pa...@google.com> #6
Fixed by Change-Id: I9060a22ec7c51e08b1f6316aa53daf2f660c805d
Description
1.8.0_05-b13x64 Oracle Corporation, Windows 8(amd64) v6.2 (1050x1680, 1920x1080, 1440x900)
Using this test plural resource, with the following sample code, produces an incorrect folded preview.
<plurals name="test_plural">
<item quantity="one">%1$s have %2$s eye</item>
<item quantity="other">%1$s have %2$s eyes</item>
</plurals>
final String name = "Cyclopses";
final int quantity = 1;
final String message = getResources().getQuantityString(R.plurals.test_plural, quantity, name, quantity);
Expected Code Folding Preview: "{Cyclopses} have {1} eye"
Observed Code Folding Preview: "{1} have {Cyclopses} eye"