Class Intl

java.lang.Object
dev.gmitch215.bytebox.builtin.Intl

public final class Intl extends Object
The platform's own locale data, exposed as itself.

The isolate already carries locale, currency and timezone data for Intl. Reaching it costs nothing, while the class library's equivalent would compile CLDR tables into the binary: String.format and its locale graph measure over 230 KB of wasm, against a hello world of 16 KB.

This is deliberately not the java.text API. It is the JavaScript one, named as such, for the cases where a standard-looking Java surface would be a lie about which rules apply. Where a Java API can be backed faithfully, it is, and that needs no separate name.

Since:
1.0.0
  • Method Details

    • number

      public static String number(double value, String locale)
      Formats a number for a locale.
      Parameters:
      value - the number
      locale - a BCP 47 tag, such as en-US
      Returns:
      the formatted number
    • number

      public static String number(double value, String locale, TSObject options)
      Formats a number with options.
      Parameters:
      value - the number
      locale - a BCP 47 tag
      options - style, currency, minimumFractionDigits and the rest
      Returns:
      the formatted number
    • currency

      public static String currency(double value, String locale, String currency)
      Formats an amount of money.
      Parameters:
      value - the amount
      locale - a BCP 47 tag
      currency - an ISO 4217 code, such as USD
      Returns:
      the formatted amount
    • dateTime

      public static String dateTime(double millis, String locale, String timeZone)
      Formats an instant in a timezone.
      Parameters:
      millis - milliseconds since the epoch
      locale - a BCP 47 tag
      timeZone - an IANA zone, such as Europe/London
      Returns:
      the formatted instant
    • dateTime

      public static String dateTime(double millis, String locale, TSObject options)
      Formats an instant with options.
      Parameters:
      millis - milliseconds since the epoch
      locale - a BCP 47 tag
      options - timeZone, dateStyle, timeStyle and the rest
      Returns:
      the formatted instant
    • relative

      public static String relative(double value, String unit, String locale)
      Formats a duration the way a person would say it, such as 3 days ago.
      Parameters:
      value - how many units, negative for the past
      unit - second, minute, hour, day, month, year
      locale - a BCP 47 tag
      Returns:
      the formatted duration
    • list

      public static String list(TSObject items, String locale)
      Joins a list the way a language does, such as a, b and c.
      Parameters:
      items - the items
      locale - a BCP 47 tag
      Returns:
      the joined list
    • compare

      public static int compare(String left, String right, String locale)
      Compares two strings the way a locale sorts them.
      Parameters:
      left - the first string
      right - the second string
      locale - a BCP 47 tag
      Returns:
      negative, zero or positive
    • timeZone

      public static String timeZone()
      Returns the timezone the runtime believes it is in, which on Workers is always UTC.
      Returns:
      the timezone the runtime believes it is in, which on Workers is always UTC
    • supports

      public static boolean supports(String locale)
      Reports whether the runtime carries data for a locale.

      Worth checking once rather than assuming: a runtime built without full ICU falls back to a single locale, and every formatter then silently produces English.

      Parameters:
      locale - a BCP 47 tag
      Returns:
      whether the runtime resolves it to itself rather than falling back