phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.47k stars 2.88k forks source link

Gettext breakage #5995

Open epinault opened 2 hours ago

epinault commented 2 hours ago

Environment

Actual behavior

I generated a brand new project.

mix phx.new generic

Upon compile the project I get the following warning

❯ mix compile
Compiling 15 files (.ex)
warning: defining a Gettext backend by calling

    use Gettext, otp_app: ...

is deprecated. To define a backend, call:

    use Gettext.Backend, otp_app: :my_app

Then, instead of importing your backend, call this in your module:

    use Gettext, backend: MyApp.Gettext

  lib/generic_web/gettext.ex:23: GenericWeb.Gettext (module)

Generated generic app

Then I fix the warning per the suggestion

and I get now on compilation

Compiling 2 files (.ex)
     error: undefined function gettext/1 (expected GenericWeb.CoreComponents to define such a function or for it to be imported, but none are available)
     │
 482 │               <span class="sr-only"><%= gettext("Actions") %></span>
     │                                         ^^^^^^^
     │
     └─ lib/generic_web/components/core_components.ex:482:41: GenericWeb.CoreComponents.table/1

    error: undefined function gettext/1 (expected GenericWeb.CoreComponents to define such a function or for it to be imported, but none are available)
    │
 76 │                   aria-label={gettext("close")}
    │                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    │
    └─ lib/generic_web/components/core_components.ex:76: GenericWeb.CoreComponents.modal/1

All the gettext are missing

Expected behavior

Gettext works correctly but does not throw a deprecated warning

epinault commented 2 hours ago

looking at https://github.com/elixir-gettext/gettext/blob/main/CHANGELOG.md#v0260, seems they changed the wya it works in 0.26 but is not generated properly

epinault commented 2 hours ago

looking at it , seems that we need to fix few things

in the core component module

defmodule GenericPhoenixAppWeb.CoreComponents do
  @moduledoc """
  Provides core UI components.

  At first glance, this module may seem daunting, but its goal is to provide
  core building blocks for your application, such as modals, tables, and
  forms. The components consist mostly of markup and are well-documented
  with doc strings and declarative assigns. You may customize and style
  them in any way you want, based on your application growth and needs.

  The default components use Tailwind CSS, a utility-first CSS framework.
  See the [Tailwind CSS documentation](https://tailwindcss.com) to learn
  how to customize them or feel free to swap in another framework altogether.

  Icons are provided by [heroicons](https://heroicons.com). See `icon/1` for usage.
  """
  use Phoenix.Component
   ##. the following line needs to go away 
   ## import  GenericPhoenixAppWeb.Gettext
   ## and instead do
  use Gettext, backend: GenericPhoenixAppWeb.Gettext

In the app_web.ex

  def controller do
    quote do
      use Phoenix.Controller,
        formats: [:html, :json],
        layouts: [html: GenericPhoenixAppWeb.Layouts]

   ##. the following line needs to go away 
   ## import  GenericPhoenixAppWeb.Gettext
   ## and instead do
      use Gettext, backend: GenericPhoenixAppWeb.Gettext

      import Plug.Conn

      unquote(verified_routes())
    end
  end
SteffenDE commented 2 hours ago

Hi @epinault, this was already fixed in https://github.com/phoenixframework/phoenix/pull/5902. We just don't have a new Phoenix version released since then.

epinault commented 1 hour ago

that it still broken on both version 1.7.14 abnd 1.7.15 from today

SteffenDE commented 1 hour ago

Note that this is only a deprecation warning and gettext still works and isn't "broken" out of the box. We know that the current situation isn't a satisfactory as it could be - we're working on getting the next Phoenix release out that will include those adjustments in the generators.