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.
Summary
Functions
Sentinel bindings that cause runtime_interpolate/2 and
do_interpolate/2 to return the translated msgid unchanged,
bypassing MF2 evaluation entirely.
Functions
@spec skip_interpolation_sentinel() :: %{__localize_skip_interpolation__: true}
Sentinel bindings that cause runtime_interpolate/2 and
do_interpolate/2 to return the translated msgid unchanged,
bypassing MF2 evaluation entirely.
Used by Localize.HTML.t/1 (and any caller that needs the raw
translated MF2 source so it can run format_to_safe_list/3 itself
for markup-aware rendering). Not intended for direct use by
application code.