An Elixir interface to internationalization functions modelled on the JavaScript Intl API.
This module delegates to the Localize library for locale-aware
formatting and provides the top-level Intl static methods:
get_canonical_locales/1 and supported_values_of/1.
The sub-modules mirror the JS Intl constructors adapted to idiomatic
Elixir: options are passed as keyword lists, return values use
{:ok, result} / {:error, reason} tuples, and bang variants are
provided for convenience.
Sub-modules
Intl.NumberFormat— locale-aware number, currency, percent, and unit formatting.Intl.DateTimeFormat— locale-aware date and time formatting.Intl.ListFormat— locale-aware list joining with conjunctions, disjunctions, or units.Intl.DisplayNames— localized display names for regions, languages, and currencies.Intl.RelativeTimeFormat— relative time strings such as "3 days ago" or "in 2 hours".Intl.PluralRules— plural category selection (zero, one, two, few, many, other).Intl.Collator— locale-aware string comparison and sorting.Intl.DurationFormat— locale-aware duration formatting.Intl.Segmenter— text segmentation into graphemes, words, or sentences.
Summary
Functions
Returns canonical locale name strings for the given locale identifiers.
Returns canonical locale name strings, raising on error.
Returns the supported values for a given internationalization key.
Functions
Returns canonical locale name strings for the given locale identifiers.
Parses and canonicalizes each locale string according to BCP 47 / RFC 5646 rules.
Arguments
localesis a locale identifier string or a list of locale identifier strings.
Returns
{:ok, list}wherelistis a list of canonical locale name strings.{:error, reason}if any locale identifier cannot be parsed.
Examples
iex> Intl.get_canonical_locales("en-us")
{:ok, ["en-US"]}
iex> Intl.get_canonical_locales(["en-us", "fr-FR"])
{:ok, ["en-US", "fr-FR"]}
Returns canonical locale name strings, raising on error.
Same as get_canonical_locales/1 but returns the list directly
or raises an exception.
Arguments
localesis a locale identifier string or a list of locale identifier strings.
Returns
- A list of canonical locale name strings.
Examples
iex> Intl.get_canonical_locales!("en-us")
["en-US"]
@spec supported_values_of(:calendar | :currency | :numbering_system | :unit) :: {:ok, list()} | {:error, term()}
Returns the supported values for a given internationalization key.
Arguments
keyis one of:calendar,:currency,:numbering_system, or:unit.
Returns
{:ok, list}wherelistis a list of supported value atoms or strings.{:error, reason}if the key is not recognized.
Examples
iex> {:ok, calendars} = Intl.supported_values_of(:calendar)
iex> :gregorian in calendars
true
iex> {:ok, systems} = Intl.supported_values_of(:numbering_system)
iex> :latn in systems
true