Generates HTML <select> tags and option lists for localized locale display.
Locales are displayed with their localized display name. A special :identity mode renders each locale's name in its own language. The list of locales, sort order, and display format are all configurable.
Summary
Functions
Generates a list of options for a locale list that can be used with Phoenix.HTML.Form.options_for_select/2 or to create a <datalist>.
Generates an HTML select tag for a locale list that can be used with a Phoenix.HTML.Form.t.
Types
@type locale() :: %{ locale: String.t(), display_name: String.t(), language_tag: Localize.LanguageTag.t() }
@type select_options() :: [ {:locales, [atom() | binary(), ...]} | {:locale, Localize.locale() | Localize.LanguageTag.t() | :identity} | {:collator, function()} | {:mapper, function()} | {:selected, atom() | binary()} | {atom(), any()} ]
Functions
@spec locale_options(select_options()) :: [tuple()] | {:error, {module(), binary()}}
Generates a list of options for a locale list that can be used with Phoenix.HTML.Form.options_for_select/2 or to create a <datalist>.
Arguments
optionsis aKeyword.t/0list of options.
Options
See Localize.HTML.Locale.select/3 for options.
Returns
A list of
{display_name, locale_string}tuples, or{:error, {module(), binary()}}if validation fails.
@spec select( form :: Phoenix.HTML.Form.t(), field :: Phoenix.HTML.Form.field(), select_options() ) :: Phoenix.HTML.safe() | {:error, {module(), binary()}}
Generates an HTML select tag for a locale list that can be used with a Phoenix.HTML.Form.t.
Arguments
formis aPhoenix.HTML.Form.t/0form.fieldis aPhoenix.HTML.Form.field/0field.optionsis aKeyword.t/0list of options.
Options
:localesdefines the list of locales to be displayed in the select tag. The default isLocalize.all_locale_ids/0with meta locales excluded.:localedefines the locale used to localise the display names. The default is the locale returned byLocalize.get_locale/0. If set to:identitythen each locale in:localeswill be rendered in its own locale.:collatoris a function used to sort the locales. The default collator sorts by display name.:mapperis a function that creates the text to be displayed in the select tag for each locale. It receives a map with:display_name,:localeand:language_tagkeys. The default mapper is&{&1.display_name, &1.locale}.:selectedidentifies the locale to be selected by default in the select tag. The default isnil.:promptis a prompt displayed at the top of the select box.
Returns
A
Phoenix.HTML.safe/0select tag, or{:error, {module(), binary()}}if validation fails.
Examples
iex> Localize.HTML.Locale.select(:my_form, :locale_list, selected: "en")