(ArgumentError) *gettext macros expect translation keys (msgid and msgid_plural)

112 views
Skip to first unread message

7...@2rba.com

unread,
Jan 2, 2018, 4:16:05 AM1/2/18
to phoenix-talk
Hello,

I am new to elixir and phoenix.
and I get into compilation error:

== Compilation error in file lib/ex_admin/paginate.ex ==
** (ArgumentError) *gettext macros expect translation keys (msgid and msgid_plural) and
domains to expand to strings at compile-time, but the given msgid
doesn't.

Dynamic translations should be avoided as they limit gettext's
ability to extract translations from your source code. If you are
sure you need dynamic lookup, you can use the functions in the Gettext
module:

    string = "hello world"
    Gettext.gettext(ExAdmin.Gettext, string)

when I check error lines, it fail on <> operator

text gettext "Displaying" <> " "

if I change the syntax without <> operator it compiles ok.

Please advise what could be wrong
Thanks
Serge

OvermindDL1

unread,
Jan 3, 2018, 5:10:48 PM1/3/18
to phoenix-talk
That is because `gettext` itself requires a static string, adding something like `<>` makes it an expression, thus no longer a static string.  To use an expression you need to do what you said in the module, so something like `text Gettext.gettext(ExAdmin.Gettext, "Displaying" <> " "`.  If however you were wanting to use `gettext("Displaying") <> " "` then you should use the parenthesis.  In general you should always use parenthesis so as to remove ambiguity.  :-)
Reply all
Reply to author
Forward
0 new messages