Cldr.HTML.Locale (Cldr HTML v1.0.0) View Source
Implements Phoenix.HTML.Form.select/4 specifically for
localised locale display.
Link to this section Summary
Functions
Generate an HTML select tag for a locale list
that can be used with a Phoenix.HTML.Form.t.
Link to this section Types
Specs
locale() :: %{
locale: String.t(),
display_name: String.t(),
language_tag: Cldr.LanguageTag.t()
}
Specs
Specs
select_options() :: [ locales: [atom() | binary(), ...], locale: Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), collator: function(), mapper: function(), backend: module(), selected: atom() | binary() ]
Link to this section Functions
Specs
select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe() | {:error, {Cldr.UnknownCurrencyError, binary()}} | {:error, {Cldr.UnknownLocaleError, binary()}}
Generate an HTML select tag for a locale list
that can be used with a Phoenix.HTML.Form.t.
Arguments
A
Phoenix.HTML.Form.t()formA
Phoenix.HTML.Form.field()fieldA
Keyword.t()list of options
Options
For select options see Phoenix.HTML.Form.select/4
:localesdefines the list of locales to be displayed in the theselecttag. The list defaults toCldr.known_locale_names/1. If:backendis specified then the list of locales known to that backend is returned. If no:backendis specified the locales known toCldr.default_backend!/0is returned.:localedefines the locale to be used to localise the description of the list of locales. The default is the locale returned byCldr.get_locale/1If set to:identitythen each locale in the:localeslist will be rendered in its own locale.:backendis any backend module. The default isCldr.default_backend!/0:collatoris a function used to sort the locales in the selection list. It is passed a list of maps where each map represents a locale. The default collator sorts bylocale_1.display_name < locale_2.display_name. As a result, default collation sorts by code point which will not return expected results for scripts other than Latin.:mapperis a function that creates the text to be displayed in the select tag for each locale. It is passed a map with three fields::display_name,:localeand:language_tag. The default mapper is&{&1.display_name, &1.locale}. Seet:locale.:selectedidentifies the locale that is to be selected by default in theselecttag. The default isnil. This is passed toPhoenix.HTML.Form.select/4:promptis a prompt displayed at the top of the select box. This is passed unmodified toPhoenix.HTML.Form.select/4
Notes
If :locale is set to :identity then each locale in
:locales will be used to render its own display name. In
this case each locale in :locales must also be configured
in the :backend or an error will be returned.
Examples
Cldr.HTML.Currency.select(:my_form, :locale_list, selected: "en")
Cldr.HTML.Currency.select(:my_form, :locale_list,
locales: ["zh-Hant", "ar", "fr"],
mapper: &({&1.display_name, &1.locale}))