guard v0.12.1 Guard.Gettext

Link to this section Summary

Link to this section Functions

Link to this macro

dgettext(domain, msgid, bindings \\ Macro.escape(%{})) (macro)

Link to this macro

dgettext_noop(domain, msgid) (macro)

Link to this macro

dngettext(domain, msgid, msgid_plural, n, bindings \\ Macro.escape(%{})) (macro)

Link to this macro

dngettext_noop(domain, msgid, msgid_plural) (macro)

Link to this macro

gettext(msgid, bindings \\ Macro.escape(%{})) (macro)

Link to this macro

gettext_comment(comment) (macro)

Link to this macro

gettext_noop(msgid) (macro)

Link to this function

handle_missing_bindings(exception, incomplete)

Default handling for missing bindings.

This function is called when there are missing bindings in a translation. It takes a Gettext.MissingBindingsError struct and the translation with the wrong bindings left as is with the %{} syntax.

For example, if something like this is called:

MyApp.Gettext.gettext("Hello %{name}, welcome to %{country}", name: "Jane", country: "Italy")

and our it/LC_MESSAGES/default.po looks like this:

msgid "Hello %{name}, welcome to %{country}"
msgstr "Ciao %{name}, benvenuto in %{cowntry}" # (typo)

then Gettext will call:

MyApp.Gettext.handle_missing_bindings(exception, "Ciao Jane, benvenuto in %{cowntry}")

where exception is a struct that looks like this:

%Gettext.MissingBindingsError{
  backend: MyApp.Gettext,
  domain: "default",
  locale: "it",
  msgid: "Hello %{name}, welcome to %{country}",
  bindings: [:country],
}

The return value of the c:handle_missing_bindings/2 callback is used as the translated string that the translation macros and functions return.

The default implementation for this function uses Logger.error/1 to warn about the missing binding and returns the translated message with the incomplete bindings.

This function can be overridden. For example, to raise when there are missing bindings:

def handle_missing_bindings(exception, _incomplete) do
  raise exception
end

Callback implementation for Gettext.Backend.handle_missing_bindings/2.

Link to this function

handle_missing_plural_translation(locale, domain, msgid, msgid_plural, n, bindings)

Default handling for plural translations with a missing translation.

Same as c:handle_missing_translation/4, but for plural translations. In this case, n is the number used for pluralizing the translated string.

Callback implementation for Gettext.Backend.handle_missing_plural_translation/6.

Link to this function

handle_missing_translation(locale, domain, msgid, bindings)

Default handling for translations with a missing translation.

When a Gettext function/macro is called with a string to translate into a locale but that locale doesn't provide a translation for that string, this callback is invoked. msgid is the string that Gettext tried to translate.

This function should return {:ok, translated} if a translation can be fetched or constructed for the given string, or {:default, msgid} otherwise.

Callback implementation for Gettext.Backend.handle_missing_translation/4.

Link to this function

lgettext(locale, domain, msgid, bindings)

Link to this function

lngettext(locale, domain, msgid, msgid_plural, n, bindings)

Link to this macro

ngettext(msgid, msgid_plural, n, bindings \\ Macro.escape(%{})) (macro)

Link to this macro

ngettext_noop(msgid, msgid_plural) (macro)