Internationalization
Elemento supports most of the classes from the Intl JavaScript API.
In addition to the actual mappings, Elemento introduces enums, implements the builder pattern, and a fluent API to create the options in a type-safe manner. Here are some examples (most of them following the MDN examples):
Date and Time Formatting
var date = new JsDate(2020, 11, 20, 3, 23, 16, 738);
// Specify default date formatting for language (locale)
console.log(new DateTimeFormat("en-US").format(date));
// Expected output: "12/20/2020"
// Specify date and time format using "style" options (i.e. full, long, medium, short)
console.log(new DateTimeFormat("en-GB", DateTimeFormatOptions.create()
.dateStyle(full)
.timeStyle(full)
.timeZone("Australia/Sydney")).format(date));
// Expected output: "Sunday, 20 December 2020 at 14:23:16 GMT+11"Duration Formatting
var duration = Duration.create()
.hours(1)
.minutes(46)
.seconds(40);
// With style set to "long" and locale "fr-FR"
new DurationFormat("fr-FR", DurationFormatOptions.create().style(long_)).format(duration);
// "1 heure, 46 minutes et 40 secondes"
// With style set to "short" and locale "en"
new DurationFormat("en", DurationFormatOptions.create().style(short_)).format(duration);
// "1 hr, 46 min and 40 sec"
// With style set to "narrow" and locale "pt"
new DurationFormat("pt", DurationFormatOptions.create().style(narrow)).format(duration);
// "1 h 46 min 40 s"
List Formatting
Number Formatting
Relative Time Formatting
Dependency
Add the following dependency to use elemento-intl:
In your GWT module, inherit from org.jboss.elemento.Intl:
Last updated