Forage.Translations (forage v0.8.0)

Utilities to easily internationalize enums that are stored in your database as strings.

Link to this section Summary

Functions

Add translations to an enum using a given Gettext backend and domain.

Translate multiple enums using the given Gettext backend and domain. The same as calling translated_enum/4 multiple times.

Link to this section Functions

Link to this macro

translated_enum(name, gettext_backend, gettext_domain, options)

(macro)

Add translations to an enum using a given Gettext backend and domain.

This macro will define a number of functions to display translated enum values to your users:

  • show_XXX/1 - shows a translated enum value. Takes the internal value as argument and returns the translated value.

  • options_for_XXX/0 - returns a list of pairs of the form {translated_user_visible_string, internal_value}. This list can be fed into Phoenix's and Forage's HTML select widgets.

  • non_empty_valid_values_for_XXX/0 - returns a list of internal enum values

  • valid_values_for_XXX/0 - returns a list of internal enum values (including the empty string)

TODO: add examples

Link to this macro

translated_enums(gettext_backend, gettext_domain, enums)

(macro)

Translate multiple enums using the given Gettext backend and domain. The same as calling translated_enum/4 multiple times.