gossamer/intl

Parent module for the Internationalization family — JavaScript’s Intl.* constructors. Hosts option types shared across siblings and top-level helpers like canonical_locales and the per-category enumerators (calendars, currencies, time_zones, etc.).

Types

How case influences sort order when case would otherwise be a tiebreaker. Maps the JavaScript caseFirst option.

pub type CaseFirst {
  Upper
  Lower
  Neither
}

Constructors

  • Upper

    Uppercase letters sort before their lowercase equivalents.

  • Lower

    Lowercase letters sort before their uppercase equivalents.

  • Neither

    Case is not considered (the JavaScript option value "false").

The clock format. Maps the JavaScript hourCycle option.

pub type HourCycle {
  H11
  H12
  H23
  H24
}

Constructors

  • H11

    12-hour clock starting at hour 0 (midnight is 0:00 AM).

  • H12

    12-hour clock starting at hour 12 (midnight is 12:00 AM — the common AM/PM clock).

  • H23

    24-hour clock starting at hour 0 (midnight is 0:00 — the common 24-hour clock).

  • H24

    24-hour clock starting at hour 24 (midnight is 24:00).

The verbosity of a rendered label. Maps the JavaScript "long" | "short" | "narrow" value set used by Intl.DateTimeFormat (weekday/era/dayPeriod), Intl.DisplayNames (style), Intl.ListFormat (style), and Intl.RelativeTimeFormat (style).

pub type LabelStyle {
  Long
  Short
  Narrow
}

Constructors

  • Long

    Full names ("Friday", "American English").

  • Short

    Shortened forms ("Fri", "AmE").

  • Narrow

    The shortest forms ("F").

The locale-matching algorithm used to pick a locale from the requested priority list. Maps the JavaScript localeMatcher option shared by the Intl.* formatter and matcher constructors.

pub type LocaleMatcher {
  BestFit
  Lookup
}

Constructors

  • BestFit

    Implementation-defined “best fit” heuristic — the runtime chooses the closest locale it supports, even when the requested tag isn’t an exact match. JavaScript’s default.

  • Lookup

    The BCP 47 Lookup algorithm — strict tag-hierarchy walk that stops at the first exact subtag prefix the runtime supports.

Which side of a formatted range produced a particular segment. Returned in the source field of format_range_to_parts output across Intl.DateTimeFormat and Intl.NumberFormat.

pub type RangePartSource {
  Start
  Shared
  End
}

Constructors

  • Start

    Produced from the start of the range.

  • Shared

    Shared by both sides of the range (e.g., a connecting " - ").

  • End

    Produced from the end of the range.

The rounding strategy applied to a formatter’s output. Maps the JavaScript roundingMode option.

pub type RoundingMode {
  RoundingModeCeil
  RoundingModeFloor
  RoundingModeExpand
  RoundingModeTrunc
  RoundingModeHalfCeil
  RoundingModeHalfFloor
  RoundingModeHalfExpand
  RoundingModeHalfTrunc
  RoundingModeHalfEven
}

Constructors

  • RoundingModeCeil

    Round toward positive infinity (toward +∞).

  • RoundingModeFloor

    Round toward negative infinity (toward -∞).

  • RoundingModeExpand

    Round away from zero.

  • RoundingModeTrunc

    Round toward zero (truncation).

  • RoundingModeHalfCeil

    Round to the nearest value; ties round toward positive infinity.

  • RoundingModeHalfFloor

    Round to the nearest value; ties round toward negative infinity.

  • RoundingModeHalfExpand

    Round to the nearest value; ties round away from zero (the default).

  • RoundingModeHalfTrunc

    Round to the nearest value; ties round toward zero.

  • RoundingModeHalfEven

    Round to the nearest value; ties round to the nearest even digit (banker’s rounding).

How rounding interacts when both significant-digit and fraction-digit options are set. Maps the JavaScript roundingPriority option.

pub type RoundingPriority {
  RoundingPriorityAuto
  RoundingPriorityMorePrecision
  RoundingPriorityLessPrecision
}

Constructors

  • RoundingPriorityAuto

    Significant digits take priority over fraction digits (the default).

  • RoundingPriorityMorePrecision

    Whichever option produces the higher number of significant digits is used.

  • RoundingPriorityLessPrecision

    Whichever option produces the lower number of significant digits is used.

Whether trailing fraction zeros are displayed on integer values. Maps the JavaScript trailingZeroDisplay option.

pub type TrailingZeroDisplay {
  TrailingZeroAuto
  TrailingZeroStripIfInteger
}

Constructors

  • TrailingZeroAuto

    Keep trailing zeros (the default).

  • TrailingZeroStripIfInteger

    Strip trailing fraction zeros from integer values (e.g., "1.00" becomes "1").

Values

pub fn calendars() -> List(String)

The calendar identifiers the runtime’s Intl implementation supports (e.g., "gregory", "buddhist"), sorted ascending.

pub fn canonical_locales(
  locales: List(String),
) -> Result(List(String), Nil)

Canonicalizes a list of BCP 47 locale tags and removes duplicates. Returns an error if any tag is malformed.

See Intl.getCanonicalLocales on MDN.

Examples

assert intl.canonical_locales(["EN-US", "Fr"]) == Ok(["en-US", "fr"])
pub fn collations() -> List(String)

The collation identifiers the runtime’s Intl implementation supports (e.g., "phonebk", "pinyin"), sorted ascending.

pub fn currencies() -> List(String)

The ISO 4217 currency codes the runtime’s Intl implementation supports (e.g., "USD", "EUR"), sorted ascending.

pub fn numbering_systems() -> List(String)

The numbering-system identifiers the runtime’s Intl implementation supports (e.g., "latn", "arab"), sorted ascending.

pub fn time_zones() -> List(String)

The IANA time-zone identifiers the runtime’s Intl implementation supports (e.g., "America/New_York"), sorted ascending.

pub fn units() -> List(String)

The measurement-unit identifiers the runtime’s Intl implementation supports (e.g., "meter", "hour"), sorted ascending.

Search Document