Warning gettext first create app & create ecto

Dear all team,

I try create first app then ecto.create, the warning show like below :

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

how to solved that ?

TLDR; Take the action stated in the deprecation message.

You’ve found yourself in a small time window when the Phoenix generators (I’m assuming you’re creating a Phoenix app?) haven’t quite caught up with a very recent change in gettext.

You can see the change and an explanation in the gettext changelog

If you make the changes stated in the deprecation message, you’ll be back on track.

4 Likes

For folks who want a push button application of this change, there is a mix task (primarily made to be a demo of igniter tooling, but also usable for this purpose) in igniter.

First, add igniter to your deps:

{:igniter, "~> 0.3"}

and then run mix igniter.update_gettext to apply the change.

EDIT: warning, igniter formats any files it touches, so you may see a larger diff than expected if you aren’t already using the formatter. You can always reject the change :slight_smile:

5 Likes

Hi, these are the changes I had to perform to get rid of this warning:

  1. Change the file lib/my_app_web.ex
  • (+/-) line 46: change from import MyAppWeb.Gettext to use Gettext, backend: MyAppWeb.Gettext;
  • (+/-) line 88: change import MyAppWeb.Gettext to use Gettext, backend: MyAppWeb.Gettext
  1. Change the file lib/my_app_web/components/core_components.ex:
  • (+/-) line 20: change import MyAppWeb.Gettext to use Gettext, backend: MyAppWeb.Gettext
  1. Change the file: lib/my_app_web/gettext.ex:
  • (+/-) line 23: change from use Gettext, otp_app: :my_app to use Gettext.Backend, otp_app: :my_app

Hope it helps

6 Likes

Thanks for the breakdown. For future reference, you can do code blocks that start with ```diff (and end with triple backticks) and you can have lines starting with + or - to demonstrate what must be added / removed. Here’s your first example:

- import MyAppWeb.Gettext
+ use Gettext, backend: MyAppWeb.Gettext
2 Likes

Good suggestion, @zachdaniel!
I was up and running again within 2 minutes. :blush:

2 Likes