gossamer/intl/locale
BCP 47 locale-identifier parsing and manipulation via the
JavaScript Intl.Locale. Parse a tag with optional extension
subtags, query its components via info, list the
calendars or collations the locale supports, and convert between
maximal and minimal canonical forms.
Types
The configuration for a Locale. Constructed from a
BCP 47 tag with optional per-component overrides.
pub opaque type Builder
A snapshot of a locale’s parsed components, returned by
info. Components with no value for the locale are
None.
pub type Info {
Info(
base_name: String,
language: String,
script: option.Option(String),
region: option.Option(String),
calendar: option.Option(String),
case_first: option.Option(intl.CaseFirst),
collation: option.Option(String),
hour_cycle: option.Option(intl.HourCycle),
numbering_system: option.Option(String),
numeric: Bool,
)
}
Constructors
-
Info( base_name: String, language: String, script: option.Option(String), region: option.Option(String), calendar: option.Option(String), case_first: option.Option(intl.CaseFirst), collation: option.Option(String), hour_cycle: option.Option(intl.HourCycle), numbering_system: option.Option(String), numeric: Bool, )Arguments
- base_name
-
The BCP 47 base name — the language, script (if any), and region (if any) joined with hyphens, without extension subtags. For
"en-US-u-ca-gregory", this is"en-US". - language
-
The language subtag (e.g.,
"en"). - script
-
The script subtag (e.g.,
"Latn","Hans"). - region
-
The region subtag (e.g.,
"US","CN"). - calendar
-
The preferred calendar identifier (e.g.,
"gregory","chinese"). - case_first
-
The preferred case-first ordering.
- collation
-
The preferred collation identifier (e.g.,
"phonebk","pinyin"). - hour_cycle
-
The preferred hour cycle.
- numbering_system
-
The preferred numbering-system identifier (e.g.,
"latn","arab"). - numeric
-
Whether numeric collation is preferred — digit runs compared as numbers rather than character by character.
A parsed BCP 47 locale identifier with optional extension subtags.
See Intl.Locale on MDN.
pub type Locale
The dominant writing direction of a locale’s primary script.
Returned by text_direction.
pub type TextDirection {
Ltr
Rtl
}
Constructors
-
LtrLeft-to-right (Latin, Cyrillic, etc.).
-
RtlRight-to-left (Arabic, Hebrew, etc.).
Values
pub fn build(builder: Builder) -> Result(Locale, Nil)
Constructs a Locale from the configured builder.
Returns Error(Nil) if the tag or any override is structurally
invalid.
pub fn calendars(locale: Locale) -> List(String)
The calendars supported by the locale, in preference order.
pub fn collations(locale: Locale) -> List(String)
The collations supported by the locale, in preference order.
pub fn hour_cycles(locale: Locale) -> List(intl.HourCycle)
The hour cycles supported by the locale, in preference order.
pub fn maximize(locale: Locale) -> Locale
Returns a locale with all subtags filled in to canonical maximal
form per the Unicode Likely Subtags algorithm (e.g., "en"
becomes "en-Latn-US").
pub fn minimize(locale: Locale) -> Locale
Returns a locale with redundant subtags removed per the Unicode
Likely Subtags algorithm (e.g., "en-Latn-US" becomes "en").
pub fn new(tag: String) -> Builder
Creates a Builder for the given BCP 47 locale tag (e.g.,
"en-US", "zh-Hans-CN").
pub fn numbering_systems(locale: Locale) -> List(String)
The numbering systems supported by the locale, in preference order.
pub fn text_direction(locale: Locale) -> TextDirection
The dominant writing direction of the locale’s primary script.
pub fn time_zones(locale: Locale) -> Result(List(String), Nil)
The IANA time zones associated with the locale’s region. Returns
Error(Nil) when the locale has no region subtag.
pub fn to_string(locale: Locale) -> String
The canonical BCP 47 string representation of the locale, including any extension subtags.
pub fn with_calendar(
builder: Builder,
calendar: String,
) -> Builder
Overrides the calendar identifier (e.g., "gregory",
"chinese").
pub fn with_case_first(
builder: Builder,
case_first: intl.CaseFirst,
) -> Builder
Overrides the case-first preference.
pub fn with_collation(
builder: Builder,
collation: String,
) -> Builder
Overrides the collation identifier (e.g., "phonebk",
"pinyin").
pub fn with_hour_cycle(
builder: Builder,
hour_cycle: intl.HourCycle,
) -> Builder
Overrides the preferred hour cycle.
pub fn with_language(
builder: Builder,
language: String,
) -> Builder
Overrides the language subtag (e.g., "en", "fr").
pub fn with_numbering_system(
builder: Builder,
numbering_system: String,
) -> Builder
Overrides the numbering-system identifier (e.g., "latn",
"arab").
pub fn with_numeric(builder: Builder, numeric: Bool) -> Builder
Overrides whether numeric collation is preferred (digit runs compared as numbers rather than character by character).
pub fn with_region(builder: Builder, region: String) -> Builder
Overrides the region subtag (e.g., "US", "CN").