From 108ea4af94fcd672fca9a3e3d8f1edcb5a9ef596 Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Wed, 23 Jan 2019 11:20:06 -0800 Subject: [PATCH] ICU-9622 Update documentation for MessageFormat and skeletons (#361) --- icu4c/source/i18n/unicode/msgfmt.h | 22 ++++++++++++---- .../src/com/ibm/icu/text/MessageFormat.java | 26 +++++++++++++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/icu4c/source/i18n/unicode/msgfmt.h b/icu4c/source/i18n/unicode/msgfmt.h index a56383517fb..8e1bf9b45f9 100644 --- a/icu4c/source/i18n/unicode/msgfmt.h +++ b/icu4c/source/i18n/unicode/msgfmt.h @@ -69,9 +69,8 @@ class NumberFormat; * if the pattern has named arguments (see {@link #usesNamedArguments()}). * *

An argument might not specify any format type. In this case, - * a Number value is formatted with a default (for the locale) NumberFormat, - * a Date value is formatted with a default (for the locale) DateFormat, - * and for any other value its toString() value is used. + * a numeric value is formatted with a default (for the locale) NumberFormat, + * and a date/time value is formatted with a default (for the locale) DateFormat. * *

An argument might specify a "simple" type for which the specified * Format object is created, cached and used. @@ -243,6 +242,19 @@ class NumberFormat; * *

* + *

Argument formatting

+ * + *

Arguments are formatted according to their type, using the default + * ICU formatters for those types, unless otherwise specified.

+ * + *

There are also several ways to control the formatting.

+ * + *

We recommend you use default styles, predefined style values, skeletons, + * or preformatted values, but not pattern strings or custom format objects.

+ * + *

For more details, see the + * ICU User Guide.

+ * *

Usage Information

* *

Here are some examples of usage: @@ -260,11 +272,11 @@ class NumberFormat; * * UnicodeString result; * MessageFormat::format( - * "At {1,time} on {1,date}, there was {2} on planet {0,number}.", + * "At {1,time,::jmm} on {1,date,::dMMMM}, there was {2} on planet {0,number}.", * arguments, 3, result, success ); * * cout << "result: " << result << endl; - * //: At 4:34:20 PM on 23-Mar-98, there was a disturbance + * //: At 4:34 PM on March 23, there was a disturbance * // in the Force on planet 7. * \endcode * diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java index 9767dd6bd9b..add6aad1808 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/MessageFormat.java @@ -259,6 +259,28 @@ import com.ibm.icu.util.ULocale.Category; * The JDK MessageFormat does create and use a ChoiceFormat object * (new ChoiceFormat(argStyleText)). * The JDK does not support plural and select arguments at all. + + *

Both the ICU and the JDK MessageFormat can control the argument + * formats by using argStyle. But the JDK MessageFormat only + * supports predefined formats and number / date / time pattern strings (which would need + * to be localized).
+ * ICU supports everything the JDK does, and also number / date / time skeletons using the + * :: prefix (which automatically yield output appropriate for the + * MessageFormat locale).

+ * + *

Argument formatting

+ * + *

Arguments are formatted according to their type, using the default + * ICU formatters for those types, unless otherwise specified. + * For unknown types, MessageFormat will call toString().

+ * + *

There are also several ways to control the formatting.

+ * + *

We recommend you use default styles, predefined style values, skeletons, + * or preformatted values, but not pattern strings or custom format objects.

+ * + *

For more details, see the + * ICU User Guide.

* *

Usage Information

* @@ -272,10 +294,10 @@ import com.ibm.icu.util.ULocale.Category; * }; * * String result = MessageFormat.format( - * "At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.", + * "At {1,time,::jmm} on {1,date,::dMMMM}, there was {2} on planet {0,number,integer}.", * arguments); * - * output: At 12:30 PM on Jul 3, 2053, there was a disturbance + * output: At 4:34 PM on March 23, there was a disturbance * in the Force on planet 7. * * -- 2.40.0