I18n Helpers v0.11.0 I18nHelpers.Ecto.Translator View Source
Link to this section 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.
Link to this section Functions
translate(data_structure, locale \\ Gettext.get_locale(), opts \\ [])
View SourceTranslates 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\0
function 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\0
function returning a list of those associations.Repeat step 1. for each associated Ecto struct.
translate!(data_structure, locale \\ Gettext.get_locale(), opts \\ [])
View SourceSame as translate/3
but raises an error if a translation is missing.