I18n Helpers v0.7.0 I18nHelpers.Form.InputHelpers View Source

Provides view helpers to render HTML input fields for text that must be provided in multiple languages. The multilingual texts passed to the form (usually in a changeset) are expected to be maps where each key represents a locale and each value contains the text for that locale. For example:

%{
  "en" => "hello world",
  "fr" => "bonjour monde",
  "nl" => "hallo wereld"
}

Link to this section Summary

Functions

Renders a text input HTML element for the given locale.

Renders multiple text input HTML elements for the given locales (one for each locale).

Renders a textarea HTML element for the given locale.

Renders multiple textarea HTML elements for the given locales (one for each locale).

Link to this section Functions

Link to this function

translated_text_input(form, field, locale, opts \\ [])

View Source

Renders a text input HTML element for the given locale.

Additional HTML attributes can be provided through opts argument.

Link to this function

translated_text_inputs(form, field, locales_or_gettext_backend, opts \\ [])

View Source

Renders multiple text input HTML elements for the given locales (one for each locale).

Options

The options allow providing additional HTML attributes, as well as:

  • :labels - an anonymous function returning the label for each generated input; the locale is given as argument
  • :wrappers - an anonymous function returning a custom wrapper for each generated input; the locale is given as argument

Example

translated_text_inputs(f, :title, [:en, :fr],
  labels: fn locale -> content_tag(:i, locale) end,
  wrappers: fn _locale -> {:div, class: "translated-input-wrapper"} end
)
Link to this function

translated_textarea(form, field, locale, opts \\ [])

View Source

Renders a textarea HTML element for the given locale.

Additional HTML attributes can be provided through opts argument.

Link to this function

translated_textareas(form, field, locales_or_gettext_backend, opts \\ [])

View Source

Renders multiple textarea HTML elements for the given locales (one for each locale).

For options, see translated_text_inputs/4