Cldr.Unit.Additional.unit_localization
unit_localization
, go back to Cldr.Unit.Additional module for more information.
Although defining a unit in config.exs
is enough to create,
operate on and serialize an additional unit, it cannot be
localised without defining localizations in an ex_cldr
backend module. For example:
defmodule MyApp.Cldr do
use Cldr.Unit.Additional
use Cldr,
locales: ["en", "fr", "de", "bs", "af", "af-NA", "se-SE"],
default_locale: "en",
providers: [Cldr.Number, Cldr.Unit, Cldr.List]
unit_localization(:person, "en", :long,
one: "{0} person",
other: "{0} people",
display_name: "people"
)
unit_localization(:person, "en", :short,
one: "{0} per",
other: "{0} pers",
display_name: "people"
)
unit_localization(:person, "en", :narrow,
one: "{0} p",
other: "{0} p",
display_name: "p"
)
end
Note the additions to a typical ex_cldr
backend module:
use Cldr.Unit.Additional
is required to define additional unitsuse of the
unit_localization/4
macro in order to define a localization.
One invocation of unit_localization
should
made for each combination of unit, locale and
style.
Parameters to unit_localization/4
unit
is the name of the additional unit as anatom
.locale
is the locale name for this localization. It should be one of the locale configured in this backend although this cannot currently be confirmed at compile tiem.style
is one of:long
,:short
, or:narrow
.localizations
is a keyword like of localization strings. Two keys -:display_name
and:other
are mandatory. They represent the localizations for a non-count display name and:other
is the localization for a unit when no other pluralization is defined.
Localisations
Localization keyword list defines localizations that match the plural rules for a given locale. Plural rules for a given number in a given locale resolve to one of six keys:
:zero
:one
(singular):two
(dual):few
(paucal):many
(also used for fractions if they have a separate class):other
(required—general plural form—also used if the language only has a single form)
Only the :other
key is required. For english,
providing keys for :one
and :other
is enough. Other
languages have different grammatical requirements.
The key :display_name
is used by the function
Cldr.Unit.display_name/1
which is primarly used
to support UI applications.