From 71825f49d70d54b581ff2680971554974dd3ae99 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Thu, 14 Jul 2011 10:24:18 -0700 Subject: cherrypick Change-Id: I48dad721d5c4d05d6026a886bb5d3b03d2ad036c docs: add info to plural strings about using string formats Change-Id: Id02c3ed8215869724092ce143e71142238098358 --- docs/html/guide/topics/resources/string-resource.jd | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/html/guide/topics/resources/string-resource.jd b/docs/html/guide/topics/resources/string-resource.jd index 2db38f1..c8a4d8f 100644 --- a/docs/html/guide/topics/resources/string-resource.jd +++ b/docs/html/guide/topics/resources/string-resource.jd @@ -107,7 +107,7 @@ ID. String string = {@link android.content.Context#getString(int) getString}(R.string.hello);

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.

@@ -233,9 +233,9 @@ the appropriate resource for you.

Note that the selection is made based on grammatical necessity. A string for zero 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, two 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:

 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);
 
+

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 +string formatting 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}.

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

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:

+is a decimal number. You can format the string with arguments from your application like this:

 Resources res = {@link android.content.Context#getResources()};
-- 
cgit v1.1