View Source Gettext.Interpolation behaviour (gettext v0.22.1)

Behaviour to provide Gettext string interpolation.

By default, Gettext uses Gettext.Interpolation.Default as the interpolation module.

Link to this section Summary

Callbacks

Called to perform interpolation at compile time.

Defines the Gettext message format to be used when extracting.

Called to perform interpolation at runtime.

Link to this section Types

Link to this type

bindings()

View Source (since 0.22.0)
@type bindings() :: %{optional(atom()) => term()}
Link to this type

translation_type()

View Source (since 0.19.0)
@type translation_type() :: :translation | :plural_translation

Link to this section Callbacks

Link to this macrocallback

compile_interpolate(translation_type, message, bindings)

View Source (since 0.19.0)
@macrocallback compile_interpolate(translation_type(), message :: String.t(), bindings()) ::
  Macro.t()

Called to perform interpolation at compile time.

Link to this callback

message_format()

View Source (since 0.19.0)
@callback message_format() :: String.t()

Defines the Gettext message format to be used when extracting.

The default interpolation module that ships with Gettext uses "elixir-format".

See the GNU Gettext documentation.

Link to this callback

runtime_interpolate(message, bindings)

View Source (since 0.19.0)
@callback runtime_interpolate(message :: String.t(), bindings()) ::
  {:ok, String.t()}
  | {:missing_bindings, partially_interpolated_message :: String.t(),
     missing_bindings :: [atom()]}

Called to perform interpolation at runtime.

If successful, should return {:ok, interpolated_string}. If there are missing bindings, should return {:missing_bindings, partially_interpolated, missing} where partially_interpolated is a string with the available bindings interpolated.