Cldr.Unit.localize
localize
, go back to Cldr.Unit module for more information.
Localizes a unit according to the current processes locale and backend.
The curent process's locale is set with
Cldr.put_locale/1
.
See Cldr.Unit.localize/3
for futher
details.
Localizes a unit according to a territory
A territory can be derived from a t:Cldr.Locale.locale_name
or t:Cldr.LangaugeTag
.
Use this function if you have a unit which
should be presented in a user interface using
units relevant to the audience. For example, a
unit #Cldr.Unit100, :meter>
might be better
presented to a US audience as #Cldr.Unit328, :foot>
.
Arguments
unit
is any unit returned byCldr.Unit.new/2
backend
is any module that includesuse Cldr
and therefore is aCldr
backend module.options
is a keyword list of options
Options
:locale
is any valid locale name returned byCldr.known_locale_names/0
or aCldr.LanguageTag
struct. The default isbackend.get_locale/0
:territory
is any valid territory code returned byCldr.known_territories/0
. The default is the territory defined as part of the:locale
. The option:territory
has a precedence over the territory in a locale.:usage
is the way in which the unit is intended to be used. The availableusage
varyies according to the unit category. SeeCldr.Unit.preferred_units/3
.
Examples
iex> unit = Cldr.Unit.new!(1.83, :meter)
iex> Cldr.Unit.localize(unit, usage: :person_height, territory: :US)
[Cldr.Unit.new!(:foot, 6), Cldr.Unit.new!(:inch, Ratio.new(6485183463413016, 137269716642252725))]