githubEdit

Internationalization

Elemento supports most of the classes from the Intlarrow-up-right 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

import static elemental2.dom.DomGlobal.console;
import static org.jboss.elemento.intl.DateTimeFormat.dateTimeFormat;
import static org.jboss.elemento.intl.DateTimeFormatOptions.dateTimeFormatOptions;
import static org.jboss.elemento.intl.Format.full;

var date = new JsDate(2020, 11, 20, 3, 23, 16, 738);

// Specify default date formatting for language (locale)
console.log(dateTimeFormat("en-US").format(new JsDate()));
// Expected output: "12/20/2020"

// Specify a date and time format using "style" options (i.e. full, long, medium, short)
console.log(dateTimeFormat("en-GB", dateTimeFormatOptions()
        .dateStyle(full)
        .timeStyle(full)
        .timeZone("Australia/Sydney")).format(date));
// Expected output: "Sunday, 20 December 2020 at 14:23:16 GMT+11"

Duration Formatting

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