Cldr.Unit.localize

You're seeing just the function 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.

Link to this function

localize(unit, backend, options \\ [])

View Source

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 by Cldr.Unit.new/2

  • backend is any module that includes use Cldr and therefore is a Cldr backend module.

  • options is a keyword list of options

Options

  • :locale is any valid locale name returned by Cldr.known_locale_names/0 or a Cldr.LanguageTag struct. The default is backend.get_locale/0

  • :territory is any valid territory code returned by Cldr.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 available usage varyies according to the unit category. See Cldr.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))]