Packages

A ~t sigil for Gettext translations, to reduce boilerplate and improve readability.

Current section

Files

Jump to
gettext_sigils lib gettext_sigils.ex
Raw

lib/gettext_sigils.ex

defmodule GettextSigils do
@moduledoc """
Imports the `~t` sigil into the module that is using this module, eg.
```elixir
use GettextSigils,
backend: MyApp.Gettext,
sigils: [
# ...
]
```
## Options
- `:sigils` - a keyword list of options for the sigil. See `GettextSigils.Options` for the available options.
- All other options are passed to `use Gettext` (eg. `:backend`).
"""
defmacro __using__(opts) do
{sigils_opts, gettext_opts} = Keyword.pop(opts, :sigils, [])
quote do
use Gettext, unquote(gettext_opts)
import GettextSigils.Sigil
@__gettext_sigils__ GettextSigils.Options.validate!(unquote(sigils_opts))
end
end
end