I’m trying to create some translations for my CMS resources, and I’m trying to automatically create Gettext domains for each resource.
defmodule MyApp.Projects.Project do
use B.Blueprint
import MyApp.Gettext
@singular "project"
@plural "projects"
# these macros basically build a map of translations
translations do
context :fields do
translate :title do
label t("Some label text")
placeholder t("Some placeholder")
end
end
end
end
The t
macro lives in the use
d B.Blueprint
and looks like this:
# ...
#
defmacro t(msgid) do
quote do
dgettext(@plural, msgid)
end
end
This doesn’t work of course:
** (ArgumentError) Gettext macros expect translation keys (msgid and msgid_plural),
domains, and comments to expand to strings at compile-time, but the given domain
doesn't. This is what the macro received:
{{:., [], [{:__aliases__, [counter: {MyApp.Projects.Project, 58}, alias: false], [:Module]}, :__get_attribute__]}, [], [{:__MODULE__, [counter: {MyApp.Projects.Project, 58}], Kernel}, :plural, 83]}
Is this doable in any way? I was hoping to not having to put all my translations in the “default.pot” file, and also not having to do t("projects", "msg here")