Browse documentation

Intl Built-ins

ECMA-402 Internationalization API reference

Implements the ECMA-402 Internationalization API. See the ECMA-402 specification for the full specification reference.

GocciaScript differences: Locale data comes from ICU: the system's library, or on WebAssembly the ICU linked into the module with the data file its host offers. Without ICU, numbers, dates, lists and display names format without locale data and collation compares code units; an embedded CLDR resource still answers locale aliases, plural categories, relative time patterns, a currency's default digits and parts of Intl.Locale's information.

Executive Summary

  • ECMA-402 conformance -- Implements the Internationalization API with locale-aware formatting for numbers, dates, lists, durations, and relative time
  • Data strategy -- ICU for formatting, collation and segmentation; an embedded CLDR resource for locale aliases, plural categories, relative time patterns, currency digits and parts of Intl.Locale's information
  • Locale negotiation -- BCP 47 locale identifiers with Unicode extension keys, best-fit and lookup matching algorithms
  • Segmentation -- Intl.Segmenter provides Unicode-aware grapheme, word, and sentence segmentation
  • Collation and display -- Intl.Collator for locale-sensitive string comparison, Intl.DisplayNames for localized display of language, region, and script names

Data Strategy

Intl takes its locale data from ICU: the system's library, ICU's own build on Windows, or on WebAssembly the ICU linked into the module (WebAssembly — ICU). There is no other source of number, date, list or display-name formatting, collation, or likely subtags: without ICU, new Intl.NumberFormat("de-DE").format(1234567.891) gives 1234567.891, Intl.DateTimeFormat formats a date as Date.prototype.toString does, Intl.Collator compares code units and new Intl.Locale("zh").maximize() stays zh.

An embedded CLDR resource answers, with or without ICU, locale aliases (iw becomes he), the plural categories Intl.PluralRules reports, the patterns Intl.RelativeTimeFormat fills, a currency's default number of digits, and parts of Intl.Locale's information, such as its hour cycles (source/engine/Goccia.Intl.pas).

Platform ICU details

PlatformLibraryNotes
macOSlibicucoreShips with the OS; available on all supported macOS versions
Linuxlibicui18nTypically provided by the libicu or icu system package
Windowsicuin79.dll, icuuc79.dll, icudt79.dllICU's own build, shipped beside the executables (ADR 0189); the system icu.dll (Windows 10 1903+) is the fallback
WebAssembly (wasm32-wasip1)ICU 79.1 linked into the module, data in icudt79l.datThe host offers the data file at /.goccia/icu; it holds 22 locales; another is not supported, so locale matching falls back to the default locale (ADR 0245)

On Windows, GocciaScript loads the newest icuin<major>.dll and icuuc<major>.dll (major 70 or later) found beside the executable or on PATH, and falls back to the system's icu.dll. Windows' icu.dll exports only part of ICU's C API: without udtitvfmt_formatCalendarToResult, formatRange cannot keep the proleptic Gregorian calendar before 1582. Release archives and CI builds for Windows carry ICU 79.1, fetched and checked by scripts/fetch-windows-icu.sh, with ICU's license as ICU-LICENSE.txt.

Intl.supportedValuesOf("currency") lists the currencies Intl.DisplayNames names in the loaded data (ECMA-402 §6.4 AvailableCanonicalCurrencies), so it follows the ICU in use: ICU 79 no longer names CNX, for example.

The embedded CLDR data is generated from upstream CLDR JSON distributions and linked as a FreePascal .res resource. Define GOCCIA_INTL_NO_EMBEDDED_CLDR at compile time to omit it.

Namespace Structure

Intl.Locale // Unicode locale identifier
Intl.Collator // Locale-sensitive string comparison
Intl.NumberFormat // Locale-sensitive number formatting
Intl.DateTimeFormat // Locale-sensitive date and time formatting
Intl.PluralRules // Plural-sensitive formatting
Intl.RelativeTimeFormat // Locale-sensitive relative time formatting
Intl.ListFormat // Locale-sensitive list formatting
Intl.DisplayNames // Locale-sensitive display names
Intl.Segmenter // Unicode segmentation
Intl.DurationFormat // Locale-sensitive duration formatting

Static methods:

MethodDescription
Intl.getCanonicalLocales(locales)Return an array of canonical locale strings
Intl.supportedValuesOf(key)Return an array of supported values for a given key ("calendar", "collation", "currency", "numberingSystem", "timeZone", "unit")

Intl.Locale

Represents a Unicode locale identifier with parsed subtags and extension keys.

Constructor / StaticDescription
new Intl.Locale(tag, options?)Create from a BCP 47 language tag string with optional override options
GetterDescription
baseNameBase locale identifier without extension keys
calendarCalendar type (Unicode ca extension)
caseFirstCase-first sort order ("upper", "lower", "false")
collationCollation type (Unicode co extension)
firstDayOfWeekFirst day of the week (Unicode fw extension, "mon"…"sun"). The option accepts weekday names and the numbers 0–7; other values throw RangeError rather than being stringified (#1268)
hourCycleHour cycle ("h11", "h12", "h23", "h24")
languageLanguage subtag
numberingSystemNumbering system (Unicode nu extension)
numericWhether numeric collation is enabled
regionRegion subtag
scriptScript subtag
variantsVariant subtags joined with - (e.g. "1996-fonipa"), or undefined
MethodDescription
maximize()Return a new Locale with likely subtags added
minimize()Return a new Locale with likely subtags removed
getCalendars()Return an array of preferred calendars
getCollations()Return an array of preferred collations
getHourCycles()Return an array of preferred hour cycles
getNumberingSystems()Return an array of preferred numbering systems
getTimeZones()Return an array of preferred time zones
getTextInfo()Return an object with direction ("ltr" or "rtl")
getWeekInfo()Return an object with firstDay and weekend
toString()Return the canonical locale string

Intl.Collator

Provides locale-sensitive string comparison.

Constructor / StaticDescription
new Intl.Collator(locales?, options?)Create a collator for the given locale(s)
Intl.Collator.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
compare(x, y)Compare two strings; returns negative, zero, or positive
resolvedOptions()Return an object reflecting the locale and collation options

Intl.NumberFormat

Provides locale-sensitive number formatting.

Constructor / StaticDescription
new Intl.NumberFormat(locales?, options?)Create a number formatter for the given locale(s)
Intl.NumberFormat.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
format(value)Format a number as a locale-specific string
formatToParts(value)Return an array of format parts with type and value
formatRange(start, end)Format a range between two numbers
formatRangeToParts(start, end)Return an array of format parts for a range
resolvedOptions()Return an object reflecting the locale and formatting options

Intl.DateTimeFormat

Provides locale-sensitive date and time formatting.

Constructor / StaticDescription
new Intl.DateTimeFormat(locales?, options?)Create a date/time formatter for the given locale(s)
Intl.DateTimeFormat.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
format(date)Format a date as a locale-specific string
formatToParts(date)Return an array of format parts with type and value
formatRange(startDate, endDate)Format a date range
formatRangeToParts(startDate, endDate)Return an array of format parts for a date range
resolvedOptions()Return an object reflecting the locale and formatting options

ICU 78 loads no abbreviated or wide month names and no era names for the iso8601 calendar (ICU-23262, fixed in ICU 79), so a date that should read January 1, 2020 AD comes out with blanks where the month and era go. When the loaded ICU lacks those names, GocciaScript formats every iso8601 date and range with ICU's Gregorian calendar data, as ICU 77 and earlier format iso8601. Names are then always present and format() and formatRange() agree; the cost is that on such an ICU, ICU's own iso8601 patterns such as 2020-01-02 for dateStyle: "short" give way to the Gregorian 1/2/20. resolvedOptions().calendar still reports iso8601, and the dates are the same in both calendars. GocciaScript checks the loaded library rather than its version, so ICU 77 and earlier, ICU 79, and an ICU 78 build with the fix applied keep their own iso8601 formatting.

Intl.PluralRules

Provides plural-sensitive formatting and plural category selection.

Constructor / StaticDescription
new Intl.PluralRules(locales?, options?)Create plural rules for the given locale(s)
Intl.PluralRules.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
select(value)Return the plural category ("zero", "one", "two", "few", "many", "other")
selectRange(start, end)Return the plural category for a range
resolvedOptions()Return an object reflecting the locale and plural options

Intl.RelativeTimeFormat

Provides locale-sensitive relative time formatting.

Constructor / StaticDescription
new Intl.RelativeTimeFormat(locales?, options?)Create a relative time formatter for the given locale(s)
Intl.RelativeTimeFormat.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
format(value, unit)Format a relative time value (e.g., "in 3 days", "2 hours ago")
formatToParts(value, unit)Return an array of format parts with type and value
resolvedOptions()Return an object reflecting the locale and formatting options

Intl.ListFormat

Provides locale-sensitive list formatting.

Constructor / StaticDescription
new Intl.ListFormat(locales?, options?)Create a list formatter for the given locale(s)
Intl.ListFormat.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
format(list)Format a list of strings (e.g., "A, B, and C")
formatToParts(list)Return an array of format parts with type and value
resolvedOptions()Return an object reflecting the locale and formatting options

Intl.DisplayNames

Provides localized display names for languages, regions, scripts, currencies, calendars, and date-time fields.

Constructor / StaticDescription
new Intl.DisplayNames(locales, options)Create a display name resolver for the given locale(s) and type
Intl.DisplayNames.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
of(code)Return the display name for the given code, or undefined
resolvedOptions()Return an object reflecting the locale and display name options

Intl.Segmenter

Provides Unicode-aware text segmentation by grapheme, word, or sentence boundaries.

Constructor / StaticDescription
new Intl.Segmenter(locales?, options?)Create a segmenter for the given locale(s) and granularity
Intl.Segmenter.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
segment(string)Return a Segments object for iterating over segments
resolvedOptions()Return an object reflecting the locale and segmentation options

Segments object:

MethodDescription
containing(index)Return the segment at the given index
[Symbol.iterator]()Iterate over segments, each with segment, index, input, and isWordLike (word granularity only)

Intl.DurationFormat

Provides locale-sensitive duration formatting.

Constructor / StaticDescription
new Intl.DurationFormat(locales?, options?)Create a duration formatter for the given locale(s)
Intl.DurationFormat.supportedLocalesOf(locales, options?)Return supported locales from the requested list
MethodDescription
format(duration)Format a duration object as a locale-specific string
formatToParts(duration)Return an array of format parts with type and value
resolvedOptions()Return an object reflecting the locale and formatting options