Icu.LanguageTag (icu v0.4.0)
Represents a locale parsed via ICU4X.
Language tags wrap a NIF resource. Use the provided parsing functions to construct values and avoid manipulating the resource directly.
Summary
Functions
Returns the parsed components of a language tag.
Returns the parsed components and raises on error.
Returns the full list of fallback locales for the given locale. "lookup" according to RFC4647.
Gets the hour cycle preference from a language tag.
Gets the hour cycle preference and raises on error.
Attempts to match the given LanguageTag.t() against a list of
gettext locales.
The maximize method potentially updates a passed in locale in place depending up the results of running the ‘Add Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
This returns a new Locale that is the result of running the ‘Remove Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
This returns a new Locale that is the result of running the 'Remove Likely Subtags, favoring script' algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
Parses a locale string and returns a language tag resource.
Parses a locale string and raises on error.
Sets the hour cycle preference on a language tag.
Sets the hour cycle preference and raises on error.
Converts a language tag resource back to its canonical string representation.
Converts a language tag resource to string and raises on error.
Types
Functions
@spec components(t()) :: {:ok, Icu.LanguageTag.Components.t()} | {:error, :invalid_resource}
Returns the parsed components of a language tag.
@spec components!(t()) :: Icu.LanguageTag.Components.t()
Returns the parsed components and raises on error.
Returns the full list of fallback locales for the given locale. "lookup" according to RFC4647.
@spec get_hour_cycle(t()) :: {:ok, hour_cycle() | nil} | {:error, :invalid_resource}
Gets the hour cycle preference from a language tag.
Returns {:ok, hour_cycle} if the tag has an hour cycle extension set,
or {:ok, nil} if no hour cycle is specified.
Examples
iex> {:ok, tag} = Icu.LanguageTag.parse("en-US-u-hc-h23")
iex> Icu.LanguageTag.get_hour_cycle(tag)
{:ok, :h23}
iex> {:ok, tag} = Icu.LanguageTag.parse("en-US")
iex> Icu.LanguageTag.get_hour_cycle(tag)
{:ok, nil}
@spec get_hour_cycle!(t()) :: hour_cycle() | nil
Gets the hour cycle preference and raises on error.
Examples
iex> tag = Icu.LanguageTag.parse!("en-US-u-hc-h12")
iex> Icu.LanguageTag.get_hour_cycle!(tag)
:h12
Attempts to match the given LanguageTag.t() against a list of
gettext locales.
Uses "lookup" according to RFC4647.
Accepts both _ and - as separators in gettext_locales.
The maximize method potentially updates a passed in locale in place depending up the results of running the ‘Add Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
This function does not guarantee that any particular set of subtags will be present in the resulting locale.
This returns a new Locale that is the result of running the ‘Remove Likely Subtags’ algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
This returns a new Locale that is the result of running the 'Remove Likely Subtags, favoring script' algorithm from https://www.unicode.org/reports/tr35/#Likely_Subtags.
@spec parse(String.t() | t()) :: {:ok, t()} | parse_error()
Parses a locale string and returns a language tag resource.
Parses a locale string and raises on error.
@spec set_hour_cycle(t(), hour_cycle()) :: {:ok, t()} | {:error, :invalid_options}
Sets the hour cycle preference on a language tag.
Returns a new language tag with the hour cycle Unicode extension (-u-hc-) set.
Hour Cycles
:h11– Hour system using 0-11 (noon = 0, midnight = 0):h12– Hour system using 1-12 (noon = 12, midnight = 12):h23– Hour system using 0-23 (noon = 12, midnight = 0)
Examples
iex> {:ok, tag} = Icu.LanguageTag.parse("en-US")
iex> {:ok, tag_with_hc} = Icu.LanguageTag.set_hour_cycle(tag, :h23)
iex> Icu.LanguageTag.to_string!(tag_with_hc)
"en-US-u-hc-h23"
@spec set_hour_cycle!(t(), hour_cycle()) :: t()
Sets the hour cycle preference and raises on error.
Examples
iex> tag = Icu.LanguageTag.parse!("en-US")
iex> tag_with_hc = Icu.LanguageTag.set_hour_cycle!(tag, :h23)
iex> Icu.LanguageTag.to_string!(tag_with_hc)
"en-US-u-hc-h23"
Converts a language tag resource back to its canonical string representation.
Converts a language tag resource to string and raises on error.