Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71825f49 authored by Scott Main's avatar Scott Main
Browse files

cherrypick Change-Id: I48dad721d5c4d05d6026a886bb5d3b03d2ad036c

docs: add info to plural strings about using string formats

Change-Id: Id02c3ed8215869724092ce143e71142238098358
parent 56def45c
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ ID.</dd>
String string = {@link android.content.Context#getString(int) getString}(R.string.hello);
</pre>
<p>You can use either {@link android.content.Context#getString(int)} or
{@link android.content.Context#getText(int)} to retieve a string. {@link
{@link android.content.Context#getText(int)} to retrieve a string. {@link
android.content.Context#getText(int)} will retain any rich text styling applied to the string.</p>

</dd> <!-- end example -->
@@ -233,9 +233,9 @@ the appropriate resource for you.

<p>Note that the selection is made based on grammatical necessity. A string for <code>zero</code>
in English 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", et cetera).
from 2, or any other number except 1 ("zero books", "one book", "two books", and so on).
Don't be misled either by the fact that, say, <code>two</code> sounds like it could only apply to
the quantity 2: a language may require that 2, 12, 102 (et cetera) are all treated like one
the quantity 2: a language may require that 2, 12, 102 (and so on) are all treated like one
another but differently to other quantities. Rely on your translator to know what distinctions
their language actually insists upon.

@@ -358,9 +358,17 @@ values, with non-exhaustive examples in parentheses:
<pre>
int count = getNumberOfsongsAvailable();
Resources res = {@link android.content.Context#getResources()};
String songsFound = res.{@link android.content.res.Resources#getQuantityString(int,int)
getQuantityString}(R.plurals.numberOfSongsAvailable, count);
String songsFound = res.{@link android.content.res.Resources#getQuantityString(int,int,int)
getQuantityString}(R.plurals.numberOfSongsAvailable, count, count);
</pre>
<p>When using the {@link android.content.res.Resources#getQuantityString(int,int,int)
getQuantityString()} method, you need to pass the {@code count} twice if your string includes
<a href="#FormattingAndStyling">string formatting</a> with a number. For example, for the string
{@code %d songs found}, the first {@count} parameter selects the appropriate plural string and the
second {@count} parameter is inserted into the {@code %d} placeholder. If your plural strings do not
include string formatting, you don't need to pass the third parameter to {@link
android.content.res.Resources#getQuantityString(int,int)
getQuantityString}.</p>
</dd> <!-- end example -->

</dl>
@@ -405,7 +413,7 @@ your format arguments in the string resource. For example, with the following re
</pre>

<p>In this example, the format string has two arguments: {@code %1$s} is a string and {@code %2$d}
is a decimal number. You can format the string with arguements from your application like this:</p>
is a decimal number. You can format the string with arguments from your application like this:</p>

<pre>
Resources res = {@link android.content.Context#getResources()};