@Deprecated public class MessageFormatter extends Object
MessageFormatter is the next iteration of MessageFormat.
This new version builds on what we learned from using MessageFormat for 20 years
in various environments, either exposed "as is" or as a base for other public APIs.
It is more modular, easier to backport, and provides extension points to add new formatters and selectors without having to modify the specification.
We will be able to add formatters for intervals, relative times, lists, measurement units, people names, and more, and support custom formatters implemented by developers outside of ICU itself, for company or even product specific needs.
MessageFormat 2 will support more complex grammatical features, such as gender, inflections, and tagging parts of the message for style changes or speech.
The reasoning for this effort is shared in the “Why MessageFormat needs a successor” document.
The “MessageFormat 2” project, which develops the new data model, semantics, and syntax, is hosted on GitHub.
The current specification for the syntax and data model can be found here.
This tech preview implements enough of the MessageFormat functions to be useful,
but the final set of functions and the parameters accepted by those functions is not yet finalized.
These are the functions interpreted right now:
datetime |
Similar to the ICU "date" and "time". |
datestyle and timestyleSimilar to argStyle : short | medium | long | full.Same values are accepted, but we can use both in one placeholder, for example {$due :datetime datestyle=full timestyle=long}.
| |
patternSimilar to argStyle = argStyleText.This is bad i18n practice, and will probably be dropped. This is included just to support migration to MessageFormat 2. | |
skeletonSame as argStyle = argSkeletonText.These are the date/time skeletons as supported by SimpleDateFormat.
| |
number |
Similar to the ICU "number". |
skeletonThese are the number skeletons as supported by NumberFormatter. | |
minimumFractionDigitsOnly implemented to be able to pass the unit tests from the ECMA tech preview implementation, which prefers options bags to skeletons. TBD if the final function will support skeletons, option backs, or both. | |
offsetUsed to support plural with an offset. | |
identity | Returns the direct string value of the argument (calling toString()). |
plural |
Similar to the ICU "plural". |
skeletonThese are the number skeletons as supported by NumberFormatter.Can also be indirect, from a local variable of type number (recommended). | |
offsetUsed to support plural with an offset. Can also be indirect, from a local variable of type number (recommended). | |
selectordinal |
Similar to the ICU "selectordinal".For now it accepts the same parameters as "plural", although there is no use case for them. TBD if this will be merged into "plural" (with some kind option) or not. |
select | Literal match, same as the ICU4 "select". |
| Modifier and Type | Class and Description |
|---|---|
static class |
MessageFormatter.Builder
Deprecated.
This API is for technology preview only.
|
| Modifier and Type | Method and Description |
|---|---|
static MessageFormatter.Builder |
builder()
Deprecated.
This API is for technology preview only.
|
FormattedMessage |
format(Map<String,Object> arguments)
Deprecated.
This API is for technology preview only.
|
String |
formatToString(Map<String,Object> arguments)
Deprecated.
This API is for technology preview only.
|
Mf2DataModel |
getDataModel()
Deprecated.
This API is for technology preview only.
|
Locale |
getLocale()
Deprecated.
This API is for technology preview only.
|
String |
getPattern()
Deprecated.
This API is for technology preview only.
|
@Deprecated public static MessageFormatter.Builder builder()
@Deprecated public Locale getLocale()
MessageFormatter.@Deprecated public String getPattern()
MessageFormatter.
If the MessageFormatter was created from an Mf2DataModel
the this string is generated from that model.
@Deprecated public Mf2DataModel getDataModel()
This data model is similar to the functionality we have today
in MessagePatternUtil maybe even a bit more higher level.
We can also imagine a model where one parses the string syntax, takes the data model,
modifies it, and then uses that modified model to create a MessageFormatter.
@Deprecated public String formatToString(Map<String,Object> arguments)
arguments - a map of objects to be formatted and substituted.IllegalArgumentException - when something goes wrong
(for example wrong argument type, or null arguments, etc.)@Deprecated public FormattedMessage format(Map<String,Object> arguments)
arguments - a map of objects to be formatted and substituted.FormattedMessage class representing the message with parameters replaced.Copyright © 2016 Unicode, Inc. and others.