VerifiedTranslations.GettextMacros (verified_translations v0.1.1)

Copy Markdown View Source

Gettext's translation macros, compiled to verified JSON translations.

use VerifiedTranslations imports these instead of Gettext.Macros' versions, so existing code keeps working while every call is verified at compile time and read from priv/translations like ~t:

gettext("Hello %{name}", name: user.name)
ngettext("1 file", "%{count} files", n)
dgettext("errors", "Not found")
pgettext("menu", "Open")

The msgid and binding names stay exactly as written, so the JSON file of gettext("Hello %{name}", name: user.name) has the msgid "Hello %{name}". A plural call is the same message as tn(n, one: "1 file", other: "%{count} files").

Msgids, domains and contexts must be compile-time strings, like Gettext requires. Bindings may be a literal keyword list or any expression evaluating to a keyword list or map.

Opt out with use VerifiedTranslations, gettext: false. Runtime functions such as Gettext.dgettext(MyAppWeb.Gettext, "errors", msg) (used by translate_error/1) are not affected.

Summary

Functions

dgettext(domain, msgid, bindings \\ [])

(macro)

dngettext(domain, msgid, msgid_plural, count, bindings \\ [])

(macro)

dpgettext(domain, context, msgid, bindings \\ [])

(macro)

dpngettext(domain, context, msgid, msgid_plural, count, bindings \\ [])

(macro)

gettext(msgid, bindings \\ [])

(macro)

ngettext(msgid, msgid_plural, count, bindings \\ [])

(macro)

pgettext(context, msgid, bindings \\ [])

(macro)

pngettext(context, msgid, msgid_plural, count, bindings \\ [])

(macro)