Localize.Message.MF1.Gettext.Interpolation (Localize MF1 v0.1.0)

Copy Markdown View Source

A Gettext interpolation module for ICU MessageFormat 1 messages.

A Gettext backend that names this module as its :interpolation formats its messages, the msgids and msgstrs of its .po files, as MF1 with Localize.Message.MF1, in the locale of Localize.get_locale/0:

defmodule MyApp.Gettext do
  use Gettext.Backend,
    otp_app: :my_app,
    interpolation: Localize.Message.MF1.Gettext.Interpolation
end

Gettext is then used as usual:

use Gettext, backend: MyApp.Gettext

gettext("You have {count, plural, one {# message} other {# messages}}", count: 3)
#=> "You have 3 messages"

This replaces a module defined with use Cldr.Gettext.Interpolation, cldr_backend: MyApp.Cldr in ex_cldr_messages; Localize has no backend modules, so there is nothing to configure. Messages written in MessageFormat 2 use Localize.Gettext.Interpolation instead.

A translation in the backend's .po files that is not valid MF1 is a compile error of the backend. Any other message that cannot be parsed or formatted is logged and returned unchanged, and a missing binding is reported to Gettext with the argument written back in its source form, as in {count, number}.