tyatin
(ArgumentError) *gettext macros expect translation keys (msgid and msgid_plural)
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:
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
Most Liked
LostKobrakai
gettext is using the elixir AST to determine if the supplied msgid is just a string or something more involved. In your case the AST for "Displaying" <> " " is no longer just a string, but something which does result in a string when being executed. The execution of it would only happen at runtime so the compiler does not yet know the resulting string to work with and therefore returns an error. One could say that the compiler should optimize away the concat operator in such cases, but it seems that’s just not the case right now.
LostKobrakai
Use the functions in the Gettext module instead of the macros of MyApp.Gettext.
thojanssens1
Thank you for the help @LostKobrakai
Can I ask you what are domain-based translations? I don’t understand:
# Simple translation
gettext("Here is one string to translate")
# Plural translation
number_of_apples = 4
ngettext("The apple is ripe", "The apples are ripe", number_of_apples)
# Domain-based translation
dgettext("errors", "Here is an error message to translate")
What is “errors” for in the last example?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








