Search documentation of Localize

# Localize.Gettext.Interpolation (Localize v0.39.0)

Copy Markdown View Source

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
    end

Now 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 from `Gettext.get_locale/1` at runtime.

## Summary

### Functions

skip_interpolation_sentinel()

Sentinel bindings that cause `runtime_interpolate/2` and `do_interpolate/2` to return the translated msgid unchanged, bypassing MF2 evaluation entirely.

## Functions

# skip_interpolation_sentinel()

    @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.