I18nHelpers.HTML.InputHelpers (I18n Helpers v0.13.0) 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 custom input HTML element filled with the translated value for the given locale. The default element is div and may be changed through the tag option.

Renders multiple custom HTML elements for the given locales (one for each locale). The default element is div and may be changed through the tag option.

Renders a text input HTML element filled with the translated value for the given locale.

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

Renders a textarea input HTML element filled with the translated value 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_element(form, field, locale, opts \\ [])

View Source

Renders a custom input HTML element filled with the translated value for the given locale. The default element is div and may be changed through the tag option.

Additional HTML attributes can be provided through opts argument.

Link to this function

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

View Source

Renders multiple custom HTML elements for the given locales (one for each locale). The default element is div and may be changed through the tag option.

For options, see translated_text_inputs/4

Link to this function

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

View Source

Renders a text input HTML element filled with the translated value 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 input HTML element filled with the translated value 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