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
-
UpperUppercase letters sort before their lowercase equivalents.
-
LowerLowercase letters sort before their uppercase equivalents.
-
NeitherCase is not considered (the JavaScript option value
"false").
The clock format. Maps the JavaScript hourCycle option.
pub type HourCycle {
H11
H12
H23
H24
}
Constructors
-
H1112-hour clock starting at hour 0 (midnight is
0:00 AM). -
H1212-hour clock starting at hour 12 (midnight is
12:00 AM— the common AM/PM clock). -
H2324-hour clock starting at hour 0 (midnight is
0:00— the common 24-hour clock). -
H2424-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
-
LongFull names (
"Friday","American English"). -
ShortShortened forms (
"Fri","AmE"). -
NarrowThe 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
-
BestFitImplementation-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.
-
LookupThe 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
-
StartProduced from the start of the range.
-
SharedShared by both sides of the range (e.g., a connecting
" - "). -
EndProduced 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
-
RoundingModeCeilRound toward positive infinity (toward
+∞). -
RoundingModeFloorRound toward negative infinity (toward
-∞). -
RoundingModeExpandRound away from zero.
-
RoundingModeTruncRound toward zero (truncation).
-
RoundingModeHalfCeilRound to the nearest value; ties round toward positive infinity.
-
RoundingModeHalfFloorRound to the nearest value; ties round toward negative infinity.
-
RoundingModeHalfExpandRound to the nearest value; ties round away from zero (the default).
-
RoundingModeHalfTruncRound to the nearest value; ties round toward zero.
-
RoundingModeHalfEvenRound 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
-
RoundingPriorityAutoSignificant digits take priority over fraction digits (the default).
-
RoundingPriorityMorePrecisionWhichever option produces the higher number of significant digits is used.
-
RoundingPriorityLessPrecisionWhichever 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
-
TrailingZeroAutoKeep trailing zeros (the default).
-
TrailingZeroStripIfIntegerStrip 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.