Locale-derived display data for unit form inputs.
Mirrors Localize.Inputs.Number.Symbols but for the unit picker —
resolves the locale's measurement system, the preferred unit
list for a category in that system, and the full list of all
known units in the category. Unit display names are localized
via Localize.Unit.display_name/2.
Categories come from Localize.Unit.known_categories/0 (e.g.
"length", "volume", "mass"). The preferred-by-system map
is a curated table per category — see @preferred_by_system
— because CLDR's per-region preference data is keyed by usage
(:person_height, :road, …) and value magnitude, not by a
simple "units that belong to system X" predicate. The curated
table covers the common categories; for everything else
preferred_units/2 falls back to the full category list.
Prefixed units (SI prefixes like decimeter, kilo*, etc.)
are filtered out by default — see :include_prefixed.
Summary
Types
Locale display data resolved by unit_for_locale/2.
Functions
Returns every known unit name in the given category.
Returns the list of unit categories known to CLDR.
Returns the curated preferred-unit names for the given
(category, system) pair, or the full category list if no
curation exists for that pair.
Resolves picker display data for the given locale + category.
Types
@type t() :: %Localize.Inputs.Number.Unit{ all_units: [{String.t(), String.t()}], category: String.t(), language_tag: Localize.LanguageTag.t(), locale: atom(), measurement_system: atom(), preferred_units: [{String.t(), String.t()}], unit: String.t() | nil, unit_display_name: String.t() | nil }
Locale display data resolved by unit_for_locale/2.
:locale— the canonical CLDR locale id (atom).:language_tag— the fullLocalize.LanguageTag.t/0.:category— the unit category as a string (e.g."length").:measurement_system— the locale's default measurement system as an atom (:metric,:us,:uk).:unit— the selected unit name as a string, ornilif the caller didn't specify one.:unit_display_name— the localized display name of the selected unit, ornil.:preferred_units— list of{name, display_name}tuples, the units in this category that belong to the locale's measurement system. Sorted in roughly small-to-large order where the curated table provides it; alphabetical otherwise.:all_units— list of{name, display_name}tuples, every known unit in the category. Alphabetical by name.
Functions
Returns every known unit name in the given category.
Arguments
category— a category string fromknown_categories/0.include_prefixed— whentrue, includes SI-prefixed variants (e.g.decimeter,kilogram-square-meter). The default isfalse.
@spec known_categories() :: [String.t()]
Returns the list of unit categories known to CLDR.
Returns
- A list of strings such as
["acceleration", "angle", "area", "length", "mass", ...].
Returns the curated preferred-unit names for the given
(category, system) pair, or the full category list if no
curation exists for that pair.
Returns
- A list of unit name strings.
@spec unit_for_locale( Localize.LanguageTag.t() | atom() | String.t() | nil, Keyword.t() ) :: {:ok, t()} | {:error, Exception.t()}
Resolves picker display data for the given locale + category.
Arguments
localeis a locale identifier (atom, string, orLocalize.LanguageTag.t/0). Defaults toLocalize.get_locale/0.optionsis a keyword list of options.
Options
:categoryis a unit category string fromLocalize.Unit.known_categories/0(e.g."length"). Required.:unitis a specific unit name to also resolve display data for. Optional.:include_prefixed— whentrue, SI-prefixed unit variants (e.g.decimeter,kilogram-square-meter) are included in the:all_unitslist. The default isfalseto keep pickers manageable. The curated preferred lists are always used as-is.
Returns
{:ok, t()}on success.{:error, Exception.t()}when the locale can't be parsed (Localize.InvalidLocaleError) or the category is unknown.
Examples
iex> {:ok, info} = Localize.Inputs.Number.Unit.unit_for_locale(:en, category: "length")
iex> info.measurement_system
:us
iex> {:ok, info} = Localize.Inputs.Number.Unit.unit_for_locale(:fr, category: "length")
iex> info.measurement_system
:metric
iex> {:ok, info} = Localize.Inputs.Number.Unit.unit_for_locale(:en, category: "length", unit: "meter")
iex> info.unit
"meter"