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.

POSIX locale names are normalized by removing encoding and modifier suffixes and replacing underscores with hyphens. The special C and POSIX locales are not language tags and are ignored.

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

all! : () => List(Locale)

Returns the preferred locales for the system or application.

Values are normalized and validated as described by get!. Invalid values are omitted, and duplicates are removed case-insensitively while preserving preference order.

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

A reason a locale string could not be parsed.