Search code examples
elixirphoenix-frameworkgettext

elixir | gettext doesn't translate some strings


I have a problem with localization of the site. An example of module which is not translated looks like this:

defmodule JpWeb.SpecialistDefinitions do
  import JpWeb.Gettext

  @specialists_search_definition %{
    schema: Jp.Profiles.Specialist,
    filters: [

      %{
        field: :is_verified,
        operation: "==",
        options: [{"Yes", true}, {"No", false}],
        label: gettext("Is verified")
      },

      %{
        field: :photo,
        operation: "is_present",
        label: gettext("With photo")
      },
    ]
  }
end

Strings in template files localized as expected.


Solution

  • With the @ syntax we’re defining a module attribute. Those are set at compile time. This means your gettext function is evaluated only once, when when you compile you code.

    So I changed the @specialists_search_definition to

    def specialists_search_definition, do:
    

    and everything worked.