Intl
The Intl namespace of Azion Runtime: its constructors for language-sensitive comparison and formatting, its static methods, and its default time zone.
The Intl object is the namespace of the ECMAScript Internationalization API. It provides language-sensitive features, such as string comparison, number formatting, and date and time formatting. Intl holds the constructors for these features, and the functions they share with other language-sensitive methods. For more information, refer to Intl on MDN Web Docs.
In a deployed function, Intl.DateTimeFormat().resolvedOptions() reports the locale en-US and the time zone UTC. A date you format without a timeZone option is formatted in UTC.
Constructors
Every constructor in this table works in a deployed function:
| Constructor | Description |
|---|---|
Intl.Collator() | Creates a collator, an object that compares strings by the rules of a language. |
Intl.DateTimeFormat() | Creates an object that formats dates and times by the rules of a language. |
Intl.DisplayNames() | Creates an object that translates the display names of languages, regions, and scripts consistently. |
Intl.ListFormat() | Creates an object that formats lists by the rules of a language. |
Intl.Locale() | Creates an object that represents a Unicode locale identifier. |
Intl.NumberFormat() | Creates an object that formats numbers by the rules of a language. |
Intl.PluralRules() | Creates an object that applies the plural rules of a language, for plural-sensitive formatting. |
Intl.RelativeTimeFormat() | Creates an object that formats relative time, such as 1 day ago, by the rules of a language. |
Intl.Segmenter() | Creates an object that splits text into segments, such as words, by the rules of a locale. |
Methods
Both methods are static: call them on Intl.
| Method | Description |
|---|---|
Intl.getCanonicalLocales(locales) | Returns the canonical names of the locales you pass. For example, ['EN-us', 'pt-br'] returns ['en-US', 'pt-BR']. |
Intl.supportedValuesOf(key) | Returns a sorted array of the unique values the implementation supports for key: calendars, collations, currencies, numbering systems, time zones, or units. |
Example
This code formats a date and a number in the form that two languages and regions expect, and logs each result. The comments show the lines that a deployed function logs:
new Date("2012-05-24") reads a date-only string as midnight UTC, and the deployed time zone is UTC, so both locales print May 24. To format a date in another time zone, pass the zone in the timeZone option. In a deployed function, new Date(0).toLocaleString('en-US', { timeZone: 'America/Sao_Paulo' }) returns 12/31/1969, 9:00:00 PM.