View Source Gettext.Macros (gettext v0.26.2)

Macros used by Gettext to provide the gettext family of functions.

Available since v0.26.0.

Macros enable users to use gettext and get automatic extraction of translations. See Gettext for more information.

The macros in this module that don't end with _with_backend are imported every time you call:

use Gettext, backend: MyApp.Gettext

Explicit backend

If you need to use the macros here with an explicit backend and you want extraction to work, you can use the _with_backend versions of the macros in this module explicitly instead.

defmodule MyApp.Gettext do
  use Gettext, otp_app: :my_app
end

defmodule MyApp.Controller do
  require Gettext.Macros

  def index(conn, _params) do
    Gettext.Macros.gettext_with_backend(MyApp.Gettext, "Hello, world!")
  end
end

Summary

Macros with Backend

Same as gettext_noop/1, but takes an explicit backend.

Comment Macros

Stores an "extracted comment" for the next message.

Extraction Macros

Marks the given message for extraction and returns it unchanged.

Marks the given message for extraction and returns {msgid, msgid_plural}.

Marks the given message for extraction and returns it unchanged.

Marks the given message for extraction and returns it unchanged.

Marks the given message for extraction and returns it unchanged.

Same as dngettext_noop("default", msgid, mgsid_plural), but will use a per-backend configured default domain if provided.

Marks the given message for extraction and returns it unchanged.

Marks the given message for extraction and returns it unchanged.

Translation Macros

Translates the given msgid in the given domain.

Translates the given plural message (msgid + msgid_plural) in the given domain.

Translates the given msgid with a given context (msgctxt) in the given domain.

Translates the given plural message (msgid + msgid_plural) with the given context (msgctxt) in the given domain.

Same as dgettext("default", msgid, %{}), but will use a per-backend configured default domain if provided.

Same as dngettext("default", msgid, msgid_plural, n, bindings), but will use a per-backend configured default domain if provided.

Translates the given msgid with the given context (msgctxt).

Translates the given plural message (msgid + msgid_plural) with the given context (msgctxt).

Macros with Backend

Link to this macro

dgettext_noop_with_backend(backend, domain, msgid)

View Source (since 0.26.0) (macro)

Same as dgettext_noop/2, but takes an explicit backend.

Link to this macro

dgettext_with_backend(backend, domain, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as dgettext/3, but takes an explicit backend.

Link to this macro

dngettext_noop_with_backend(backend, domain, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Same as dngettext_noop/3, but takes an explicit backend.

Link to this macro

dngettext_with_backend(backend, domain, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as dngettext/5, but takes an explicit backend.

Link to this macro

dpgettext_noop_with_backend(backend, domain, msgctxt, msgid)

View Source (since 0.26.0) (macro)

Same as dpgettext_noop/3, but takes an explicit backend.

Link to this macro

dpgettext_with_backend(backend, domain, msgctxt, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as dpgettext/4, but takes an explicit backend.

Link to this macro

dpngettext_noop_with_backend(backend, domain, msgctxt, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Same as dpngettext_noop/4, but takes an explicit backend.

Link to this macro

dpngettext_with_backend(backend, domain, msgctxt, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as dpngettext/6, but takes an explicit backend.

Link to this macro

gettext_noop_with_backend(backend, msgid)

View Source (since 0.26.0) (macro)

Same as gettext_noop/1, but takes an explicit backend.

Link to this macro

gettext_with_backend(backend, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as gettext/2, but takes an explicit backend.

Link to this macro

ngettext_noop_with_backend(backend, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Same as ngettext_noop/2, but takes an explicit backend.

Link to this macro

ngettext_with_backend(backend, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as ngettext/4, but takes an explicit backend.

Link to this macro

pgettext_noop_with_backend(backend, msgctxt, msgid)

View Source (since 0.26.0) (macro)

Same as pgettext_noop/2, but takes an explicit backend.

Link to this macro

pgettext_with_backend(backend, msgctxt, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as pgettext/3, but takes an explicit backend.

Link to this macro

pngettext_noop_with_backend(backend, msgctxt, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Same as pngettext_noop/3, but takes an explicit backend.

Link to this macro

pngettext_with_backend(backend, msgctxt, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Same as pngettext/5, but takes an explicit backend.

Comment Macros

Link to this macro

gettext_comment(comment)

View Source (since 0.26.0) (macro)

Stores an "extracted comment" for the next message.

This macro can be used to add comments (Gettext refers to such comments as extracted comments) to the next message that will be extracted. Extracted comments will be prefixed with #. in POT files.

Calling this function multiple times will accumulate the comments; when another Gettext macro (such as gettext/2) is called, the comments will be extracted and attached to that message, and they will be flushed so as to start again.

This macro always returns :ok.

Examples

gettext_comment("The next message is awesome")
gettext_comment("Another comment for the next message")
gettext("The awesome message")

Extraction Macros

Link to this macro

dgettext_noop(domain, msgid)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

dgettext_noop("errors", "Error found!")
#=> "Error found!"
Link to this macro

dngettext_noop(domain, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns {msgid, msgid_plural}.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value of this macro is {msgid, msgid_plural}.

Examples

my_fun = fn {msgid, msgid_plural} ->
  # do something with msgid and msgid_plural
end

my_fun.(dngettext_noop("errors", "One error", "%{count} errors"))
Link to this macro

dpgettext_noop(domain, msgctxt, msgid)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

dpgettext_noop("errors", "Home page", "Error found!")
#=> "Error found!"
Link to this macro

dpngettext_noop(domain, msgctxt, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

dpngettext_noop("errors", "Home page", "Error found!", "Errors found!")
#=> "Error found!"
Link to this macro

gettext_noop(msgid)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

gettext_noop("Error found!")
#=> "Error found!"
Link to this macro

ngettext_noop(msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Same as dngettext_noop("default", msgid, mgsid_plural), but will use a per-backend configured default domain if provided.

Link to this macro

pgettext_noop(msgid, context)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

pgettext_noop("Error found!", "Home page")
#=> "Error found!"
Link to this macro

pngettext_noop(msgctxt, msgid, msgid_plural)

View Source (since 0.26.0) (macro)

Marks the given message for extraction and returns it unchanged.

This macro can be used to mark a message for extraction when mix gettext.extract is run. The return value is the given string, so that this macro can be used seamlessly in place of the string to extract.

Examples

pngettext_noop("Home page", "Error found!", "Errors found!")
#=> "Error found!"

Translation Macros

Link to this macro

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

View Source (since 0.26.0) (macro)

Translates the given msgid in the given domain.

bindings is a map of bindings to support interpolation.

See also Gettext.dgettext/4.

Link to this macro

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

View Source (since 0.26.0) (macro)

Translates the given plural message (msgid + msgid_plural) in the given domain.

n is an integer used to determine how to pluralize the message. bindings is a map of bindings to support interpolation.

See also Gettext.dngettext/6.

Link to this macro

dpgettext(domain, msgctxt, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Translates the given msgid with a given context (msgctxt) in the given domain.

bindings is a map of bindings to support interpolation.

See also Gettext.dpgettext/5.

Link to this macro

dpngettext(domain, msgctxt, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Translates the given plural message (msgid + msgid_plural) with the given context (msgctxt) in the given domain.

n is an integer used to determine how to pluralize the message. bindings is a map of bindings to support interpolation.

See also Gettext.dpngettext/7.

Link to this macro

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

View Source (since 0.26.0) (macro)

Same as dgettext("default", msgid, %{}), but will use a per-backend configured default domain if provided.

See also Gettext.gettext/3.

Link to this macro

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

View Source (since 0.26.0) (macro)

Same as dngettext("default", msgid, msgid_plural, n, bindings), but will use a per-backend configured default domain if provided.

See also Gettext.ngettext/5.

Link to this macro

pgettext(msgctxt, msgid, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Translates the given msgid with the given context (msgctxt).

bindings is a map of bindings to support interpolation.

See also Gettext.pgettext/4.

Link to this macro

pngettext(msgctxt, msgid, msgid_plural, n, bindings \\ Macro.escape(%{}))

View Source (since 0.26.0) (macro)

Translates the given plural message (msgid + msgid_plural) with the given context (msgctxt).

n is an integer used to determine how to pluralize the message. bindings is a map of bindings to support interpolation.

See also Gettext.pngettext/6.