I18n Helpers v0.5.1 I18nHelpers.Ecto.Translator View Source

Link to this section Summary

Functions

Returns a closure allowing to memorize the given options for translate\3.

Translates an Ecto struct, a list of Ecto structs or a map containing translations.

Link to this section Functions

Returns a closure allowing to memorize the given options for translate\3.

Link to this function

translate(data_structure, locale \\ Gettext.get_locale(), opts \\ [])

View Source
translate(list() | struct() | map(), String.t(), keyword()) ::
  list() | struct() | String.t() | nil

Translates an Ecto struct, a list of Ecto structs or a map containing translations.

Translating an Ecto struct for a given locale consists of the following steps:

  1. Get the list of the fields that need to be translated from the Schema. The Schema must contain a get_translatable_fields\0 function returning a list of those fields.

  2. Get the text for the given locale and store it into a virtual field. The Schema must provide, for each translatable field, a corresponding virtual field in order to store the translation.

  3. Get the list of the associations that also need to be translated from the Schema. The Schema must contain a get_translatable_assocs\0 function returning a list of those associations.

  4. Repeat step 1. for each associated Ecto struct.