View Source I18nHelpers.Ecto.Translator (I18n Helpers v0.14.0)
Summary
Functions
Translates an Ecto struct, a list of Ecto structs or a map containing translations.
Same as translate/3 but raises an error if a translation is missing.
Functions
translate(data_structure, locale \\ Gettext.get_locale(), opts \\ [])
View Source@spec translate(list() | struct() | map(), list() | String.t() | atom(), keyword()) :: list() | struct() | String.t()
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:
Get the list of the fields that need to be translated from the Schema. The Schema must contain a
get_translatable_fields\0function returning a list of those fields.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.
Get the list of the associations that also need to be translated from the Schema. The Schema must contain a
get_translatable_assocs\0function returning a list of those associations.Repeat step 1. for each associated Ecto struct.
translate!(data_structure, locale \\ Gettext.get_locale(), opts \\ [])
View Source@spec translate!(list() | struct() | map(), list() | String.t() | atom(), keyword()) :: list() | struct() | String.t()
Same as translate/3 but raises an error if a translation is missing.