pieterm
Gettext usage in LiveView templates (leex) not picked up via mix.gettext
When using something like:
<%= Gettext.gettext(JustifiedWeb.Gettext, "Entiteit") %>
in LiveView templates (.leex) and when running
mix gettext.extract
mix gettext.merge priv/gettext
to extract and merge all gettext references to our .pot and .po files.
These references never get picked up. I could add the msgid and msgstr manually, but those are overwritten when extracting and merging again.
Is there some configuration setting that I’m missing? A place I forgot to import Gettext?
Marked As Solved
pieterm
I think I found the solution while testing the reply of @wmnnd
Apparently, you need to import import YourAppWeb.Gettext into the corresponding live module of the leex template.
Works:
defmodule YourAppWeb.SomethingLive do
use Phoenix.LiveView
use Phoenix.HTML
import YourAppWeb.Gettext
def mount(_, _, socket) do
{:ok, socket}
end
end
<%= gettext("Entiteit") %>
Does not work:
defmodule YourAppWeb.SomethingLive do
use Phoenix.LiveView
use Phoenix.HTML
# import YourAppWeb.Gettext
def mount(_, _, socket) do
{:ok, socket}
end
end
<%= gettext("Entiteit") %>
Now, it seems obvious. ![]()
Also Liked
seb3s
Hello
I put it in the app_web.ex file in the view_helpers function so it is available from everywhere.
cheers,
Sébastien.
sschuth
Stumbled across your message a bit late, but maybe my findings are still helpful, or helpful to others – I had the same error when mistakenly doing something like this:
defmodule FooWeb.SomeComponent
use Phoenix.LiveComponent
# ...
end
Instead, you are supposed to use the macros generated for you:
defmodule FooWeb.SomeComponent
use FooWeb, :live_component
# ...
end
This way, all view helpers are imported – basically that is everything the use FooWeb, :live_component macro does (at least in code generated using liveview version 0.15.5) in addition to use Phoenix.LiveComponent, so it takes some time until you find out that you have some functionality missing.
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









