Locale
Bindings to JavaScript's Intl.Locale.
t
type toptions
type options = {
baseName?: string,
calendar?: Intl_Common.calendar,
collation?: Intl_Common.collation,
hourCycle?: [#h11 | #h12 | #h23 | #h24],
caseFirst?: [#"false" | #lower | #upper],
numberingSystem?: Intl_Common.numberingSystem,
numeric?: bool,
language?: string,
script?: string,
region?: string,
}make
let make: (string, ~options: options=?) => tCreates a new Intl.Locale object from a locale identifier and optional modifiers.
See Intl.Locale on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en-US")
locale->Intl.Locale.language == "en"
baseName
let baseName: t => stringbaseName(locale) returns the canonical base name (without Unicode extensions).
See Intl.Locale.prototype.baseName on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("fr-CA")
locale->Intl.Locale.baseName == "fr-CA"
calendar
let calendar: t => option<string>calendar(locale) returns the specified calendar, if present.
See Intl.Locale.prototype.calendar on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={calendar: #gregory})
locale->Intl.Locale.calendar == Some("gregory")
caseFirst
let caseFirst: t => option<string>caseFirst(locale) returns the case-first ordering setting, if present.
See Intl.Locale.prototype.caseFirst on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={caseFirst: #upper})
locale->Intl.Locale.caseFirst == Some("upper")
collation
let collation: t => option<string>collation(locale) returns the collation type, if present.
See Intl.Locale.prototype.collation on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={collation: #phonebk})
locale->Intl.Locale.collation == Some("phonebk")
hourCycle
let hourCycle: t => option<string>hourCycle(locale) returns the preferred hour cycle, if present.
See Intl.Locale.prototype.hourCycle on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={hourCycle: #h12})
locale->Intl.Locale.hourCycle == Some("h12")
language
let language: t => stringlanguage(locale) returns the primary language subtag.
See Intl.Locale.prototype.language on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("pt-BR")
locale->Intl.Locale.language == "pt"
numberingSystem
let numberingSystem: t => option<string>numberingSystem(locale) returns the numbering system identifier, if present.
See Intl.Locale.prototype.numberingSystem on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={numberingSystem: #latn})
locale->Intl.Locale.numberingSystem == Some("latn")
numeric
let numeric: t => boolnumeric(locale) indicates whether numeric ordering should be used for region subtags.
See Intl.Locale.prototype.numeric on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en", ~options={numeric: true})
locale->Intl.Locale.numeric == true
region
let region: t => option<string>region(locale) returns the region subtag, if present.
See Intl.Locale.prototype.region on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en-US")
locale->Intl.Locale.region == Some("US")
script
let script: t => option<string>script(locale) returns the script subtag, if present.
See Intl.Locale.prototype.script on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("sr-Cyrl")
locale->Intl.Locale.script == Some("Cyrl")
maximize
let maximize: t => tmaximize(locale) adds likely subtags to produce the most specific locale.
See Intl.Locale.prototype.maximize on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en")
locale->Intl.Locale.maximize->Intl.Locale.region == Some("US")
minimize
let minimize: t => tminimize(locale) removes unnecessary subtags while preserving semantics.
See Intl.Locale.prototype.minimize on MDN.
Examples
RESCRIPTlet locale = Intl.Locale.make("en-Latn-US")
locale->Intl.Locale.minimize->Intl.Locale.baseName == "en"
ignore
let ignore: t => unitignore(locale) ignores the provided locale and returns unit.
This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.