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 dgettext_noop/2
, but takes an explicit backend.
Same as dgettext/3
, but takes an explicit backend.
Same as dngettext_noop/3
, but takes an explicit backend.
Same as dngettext/5
, but takes an explicit backend.
Same as dpgettext_noop/3
, but takes an explicit backend.
Same as dpgettext/4
, but takes an explicit backend.
Same as dpngettext_noop/4
, but takes an explicit backend.
Same as dpngettext/6
, but takes an explicit backend.
Same as gettext_noop/1
, but takes an explicit backend.
Same as gettext/2
, but takes an explicit backend.
Same as ngettext_noop/2
, but takes an explicit backend.
Same as ngettext/4
, but takes an explicit backend.
Same as pgettext_noop/2
, but takes an explicit backend.
Same as pgettext/3
, but takes an explicit backend.
Same as pngettext_noop/3
, but takes an explicit backend.
Same as pngettext/5
, 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
dgettext_noop_with_backend(backend, domain, msgid)
View Source (since 0.26.0) (macro)Same as dgettext_noop/2
, but takes an explicit backend.
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.
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.
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.
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.
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.
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.
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.
Same as gettext_noop/1
, but takes an explicit backend.
gettext_with_backend(backend, msgid, bindings \\ Macro.escape(%{}))
View Source (since 0.26.0) (macro)Same as gettext/2
, but takes an explicit backend.
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.
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.
pgettext_noop_with_backend(backend, msgctxt, msgid)
View Source (since 0.26.0) (macro)Same as pgettext_noop/2
, but takes an explicit backend.
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.
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.
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.
Extraction Macros
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!"
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"))
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!"
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!"
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!"
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.
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!"
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
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
.
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
.
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
.
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
.
Same as dgettext("default", msgid, %{})
, but will use a per-backend
configured default domain if provided.
See also Gettext.gettext/3
.
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
.
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
.
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
.
Comment Macros
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