Locale-sensitive list formatting, modelled on
Intl.ListFormat.
Joins a list of items into a human-readable string using locale-appropriate conjunctions ("and"), disjunctions ("or"), or unit-style separators.
Delegates to Localize.List for the underlying formatting.
Summary
Functions
Formats a list into a locale-aware string.
Formats a list into a locale-aware string, raising on error.
Functions
Formats a list into a locale-aware string.
Arguments
listis a list of terms that implementString.Chars.optionsis a keyword list of options.
Options
:localeis a locale identifier string or atom. The default is the current process locale.:typeis:conjunction,:disjunction, or:unit. The default is:conjunction.:styleis:long,:short, or:narrow. The default is:long.
Returns
{:ok, formatted_string}on success.{:error, reason}if the locale or options are invalid.
Examples
iex> Intl.ListFormat.format(["a", "b", "c"], locale: :en)
{:ok, "a, b, and c"}
iex> Intl.ListFormat.format(["a", "b", "c"], locale: :en, type: :disjunction)
{:ok, "a, b, or c"}
iex> Intl.ListFormat.format(["a", "b"], locale: :en, type: :unit, style: :narrow)
{:ok, "a b"}
Formats a list into a locale-aware string, raising on error.
Same as format/2 but returns the string directly or raises.
Arguments
listis a list of terms that implementString.Chars.optionsis a keyword list of options.
Returns
- A formatted string.
Examples
iex> Intl.ListFormat.format!(["a", "b", "c"], locale: :en)
"a, b, and c"