Gettext.extract not consider views

In a view of my project i have this method:

def page_title(:new, assigns) do
    if is_nil(assigns.changeset.data.contest_id) do
      Gettext.gettext(ShuttertopWeb.Gettext, "Nuovo contest")
    else
      "#{assigns.changeset.data.name} · #{Gettext.gettext(ShuttertopWeb.Gettext, "Nuova edizione")}"
    end
  end

If i try to launch the command:
mix gettext.extract --merge

the msgid: “Nuovo contest” and the msgid: “Nuova edizione” aren’t inserted in the gettext .po or in .pot files

How can i do it without insert them manually?

Thanks

Have you tried this sequence of commands?

mix gettext.extract
mix gettext.merge priv/gettext # Can append --no-fuzzy if you want only exact key matches.

Yes but nothing changed

Hi, i changed
Gettext.gettext(ShuttertopWeb.Gettext, "Nuovo contest")
in
gettext("Nuovo contest")

and now

mix gettext.extract
mix gettext.merge priv/gettext

insert the msgid: “Nuovo contest” in default.po

The issue is that i have the analog situation in view_helper

defmodule ShuttertopWeb.ViewHelpers do
  @moduledoc false
  use Phoenix.HTML
...
def get_country_name(country_id) do
    if !is_nil(country_id) && country_id != "" do
      c = Enum.at(Countries.filter_by(:alpha2, country_id), 0)
      c.name
    else
      Gettext.gettext(ShuttertopWeb.Gettext, "Mondo")
    end
  end

But if i use gettext("Mondo") i receive the error: undefined function gettext

Any suggestion?

Thanks!

Are you importing the Gettext module somewhere?

import MyAppWeb.Gettext

1 Like