MessageFormat partially supports ListFormat, CompactNumberFormat, and DateTimeFormatter through the setter methods. However, MessageFormat does not support them via the pattern syntax. Both through applyPattern() and toPattern().
The specification of toPattern() could also be improved, as it cannot produce patterns for the mentioned classes, as well as for any user-defined subclasses of Format. For example,
MessageFormat first = new MessageFormat("{0}");
first.setFormatByArgumentIndex(0, new ChoiceFormat("0#foo"));
first.toPattern(); // returns "{0,choice,0.0#foo}"
MessageFormat second = new MessageFormat("{0}");
second.setFormatByArgumentIndex(0, NumberFormat.getCompactNumberInstance(second.getLocale(), NumberFormat.Style.SHORT));
second.toPattern(); // returns "{0}"
The specification of toPattern() could also be improved, as it cannot produce patterns for the mentioned classes, as well as for any user-defined subclasses of Format. For example,
MessageFormat first = new MessageFormat("{0}");
first.setFormatByArgumentIndex(0, new ChoiceFormat("0#foo"));
first.toPattern(); // returns "{0,choice,0.0#foo}"
MessageFormat second = new MessageFormat("{0}");
second.setFormatByArgumentIndex(0, NumberFormat.getCompactNumberInstance(second.getLocale(), NumberFormat.Style.SHORT));
second.toPattern(); // returns "{0}"
- csr for
-
JDK-8319344 MessageFormat pattern support for CompactNumberFormat, ListFormat, and DateTimeFormatter
-
- Closed
-
- duplicates
-
JDK-8254654 java.text.MessageFormat method format, line 1272 can't work with LocalDate
-
- Closed
-
- relates to
-
JDK-8329118 Run MessageFormat additional subformat pattern tests under en_US locale
-
- Resolved
-