pieterm

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

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. :slight_smile:

Also Liked

seb3s

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

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.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
vac
Hi, I’m quite new in Elixir and I’m trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and I...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement