Locale

Locale :: # (opaque)

A locale represented as a pragmatically validated BCP 47 language tag.

Locale spelling is preserved for display, while equality and hashing are ASCII case-insensitive as required for language tags.

parse : Str -> Try(Locale, ParseErr)

Parse a dynamic string as a locale.

This catches common language-tag mistakes without consulting the IANA registry or implementing every structural rule in BCP 47.

from_quote : Str -> Try(Locale, [BadQuotedBytes(Str)])

Parse and validate a quoted locale literal.

Roc calls this automatically when a quoted literal is expected to have type Locale.

parser_for : encoding -> state -> Try({ value : Locale, rest : state }, err) where [ encoding.parse_str : encoding, state -> Try({ value : Str, rest : state }, err), encoding.invalid_value : encoding, state -> err, ]

Parse a locale from a string value supplied by a generic encoding.

encoder_for : encoding -> Locale, state -> Try(state, err) where [ encoding.encode_str : Str, state -> Try(state, err), ]

Encode a locale using its original spelling through a generic encoding.

to_str : Locale -> Str

Return the locale using its original spelling.

to_inspect : Locale -> Str

Render a locale for debugging and test failures.

is_eq : Locale, Locale -> Bool

Compare locale tags without ASCII case distinctions.

get! : => Try(Locale, [NotAvailable, ..])

Returns the most preferred locale for the system or application.

Host locale strings are trusted because the platform host is responsible for returning BCP 47 language tags.

Returns Err(NotAvailable) if the locale cannot be determined.

all! : => List(Locale)

Returns the preferred locales for the system or application.

Host locale strings are trusted because the platform host is responsible for returning BCP 47 language tags.

ParseErr : [ Empty, EmptySubtag, InvalidCharacter, InvalidLanguage, MissingExtensionValue, SubtagTooLong, ]

A reason a locale string could not be parsed.