Gettext interpolation module for ICU MessageFormat 2 (MF2) messages.
Implements the Gettext.Interpolation behaviour so that MF2 messages
can be used in Gettext .po/.pot files. At compile time, messages
are parsed into an AST for efficient runtime formatting. At runtime,
bindings are interpolated using Localize.Message.
Defining a Gettext module with MF2 interpolation
defmodule MyApp.Gettext do
use Gettext.Backend,
otp_app: :my_app,
interpolation: Localize.Gettext.Interpolation
endNow Gettext macros will parse and format MF2 messages:
import MyApp.Gettext
gettext("{{Hello {$name}!}}", %{name: "World"})
#=> "Hello World!"Options
The use macro accepts the following options:
:locale- a default locale to use for formatting. When not set, the locale is resolved fromGettext.get_locale/1at runtime.