Localize.HTML (Localize Web v0.7.0)

Copy Markdown View Source

Facade module providing HTML form select helpers for localized data.

This module delegates to specialized submodules that generate <select> tags and option lists for currencies, territories, locales, units of measure, and months. Each helper localizes display names according to the current or specified locale using the Localize library.

Delegate Functions

Summary

Functions

currency_options(options)

See Localize.HTML.Currency.currency_options/1.

currency_select(form, field, options)

See Localize.HTML.Currency.select/3.

locale_options(options)

See Localize.HTML.Locale.locale_options/1.

locale_select(form, field, options)

See Localize.HTML.Locale.select/3.

message(assigns)

See Localize.HTML.Message.message/1.

month_options(options)

See Localize.HTML.Month.month_options/1.

month_select(form, field, options)

See Localize.HTML.Month.select/3.

t(msgid)

(macro)

Translates an MF2 message at compile time and renders it (including inline markup) at runtime.

This is the macro-form equivalent of ~t + <.message> combined. Suitable for use directly inside HEEx body interpolation:

<h1>{t("Hello, #{@user.name}!")}</h1>
<p>{t("By signing up you accept our {#link navigate=|/terms|}terms{/link}.")}</p>

Elixir-style #{expr} interpolations are rewritten as MF2 {$name} placeholders at compile time using the same key-derivation rules as the ~t sigil (see Localize.Message.Sigils). The canonical msgid is registered with Gettext for translation extraction; at runtime the translated message is walked via Localize.Message.format_to_safe_list/3 so MF2 markup tags such as {#bold}…{/bold} and {#link href=…}…{/link} are dispatched to the Phoenix function components registered with Localize.HTML.Message.

The calling module must opt in with:

use Localize.Message.Sigils, backend: MyApp.Gettext

Arguments

  • msgid is an MF2 message string literal. May contain Elixir #{expr} interpolations.

  • options is a keyword list of options (only t/2).

Options

  • :locale overrides the current locale for this render only. The default is Localize.get_locale/0.

  • :components is a map of %{markup_name => renderer_fun} that overrides the default markup component registry for this render only. The default is %{}.

Returns

  • A Phoenix.HTML.safe() value suitable for HEEx interpolation.

Examples

{t("Hello, world!")}
{t("Hello, #{name}!")}
{t("Read {#bold}#{count} item(s){/bold}")}
{t("Click {#link patch=|/x|}here{/link}", locale: :fr)}

t(msgid, options)

(macro)

territory_options(options)

See Localize.HTML.Territory.territory_options/1.

territory_select(form, field, options)

See Localize.HTML.Territory.select/3.

unit_options(options)

See Localize.HTML.Unit.unit_options/1.

unit_select(form, field, options)

See Localize.HTML.Unit.select/3.