Repository: elixir-gettext/gettext
Pull request #406 (2024-12-07 05:57:22)

Deprecation message
Updated deprecation message to include more details. 

coveralls: ## Pull Request Test Coverage Report for [Build 4484498a5f4559e71463cc46d670df345acc7a71-PR-406](https://coveralls.io/builds/71240901)


### Details

* **2** of **2**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.02%**) to **91.908%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/71240901/badge)](https://coveralls.io/builds/71240901) |
| :-- | --: |
| Change from base [Build 30fe4690d55b6d4862c93667b9499587aa3610c8](https://coveralls.io/builds/71225378): |  0.02% |
| Covered Lines: | 636 |
| Relevant Lines: | 692 |

---
##### 💛  - [Coveralls](https://coveralls.io)

whatyouhide: Fantastic job, spotless! 💟 

Patch:
diff --git a/README.md b/README.md
index 6a4dc8b..13e7c92 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@ dgettext("errors", "Here is an error message to translate")
 
 Messages in Gettext are stored in Portable Object files (`.po`). Such files must be placed at `priv/gettext/LOCALE/LC_MESSAGES/DOMAIN.po`, where `LOCALE` is the locale and `DOMAIN` is the domain (the default domain is called `default`).
 
-For example, the message to `pt_BR` of the first two `*gettext` calls in the snippet above must be placed in the `priv/gettext/pt_BR/LC_MESSAGES/default.po` file with contents:
+For example, the messages for `pt_BR` from the first two `*gettext` calls in the snippet above must be placed in the `priv/gettext/pt_BR/LC_MESSAGES/default.po` file with the following contents:
 
 ```pot
 msgid "Here is one string to translate"
@@ -60,7 +60,7 @@ msgstr[0] "Aqui está o texto para traduzir"
 msgstr[1] "Aqui estão os textos para traduzir"
 ```
 
-`.po` are text-based files and can be edited directly by translators. Some may even use existing tools for managing them, such as [Poedit][poedit] or [poeditor.com][poeditor.com].
+`.po` files are text-based and can be edited directly by translators. Some may even use existing tools for managing them, such as [Poedit][poedit] or [poeditor.com][poeditor.com].
 
 Finally, because messages are based on strings, your source code does not lose readability as you still see literal strings, like `gettext("here is an example")`, instead of paths like `translate("some.path.convention")`.
 
diff --git a/lib/gettext.ex b/lib/gettext.ex
index b2eea3d..cb4de15 100644
--- a/lib/gettext.ex
+++ b/lib/gettext.ex
@@ -636,19 +636,25 @@ defmodule Gettext do
 
       _other ->
         # TODO: remove this once we stop supporting the old way of defining backends.
+        otp_app = Keyword.get(opts, :otp_app, :my_app)
+
         IO.warn(
           """
-          defining a Gettext backend by calling
+          Defining a Gettext backend by calling:
 
-              use Gettext, otp_app: ...
+              use Gettext, otp_app: #{inspect(otp_app)}
 
           is deprecated. To define a backend, call:
 
-              use Gettext.Backend, otp_app: :my_app
+              use Gettext.Backend, otp_app: #{inspect(otp_app)}
+
+          Then, replace importing your backend:
+
+              import #{inspect(__CALLER__.module)}
 
-          Then, instead of importing your backend, call this in your module:
+          with calling this in your module:
 
-              use Gettext, backend: MyApp.Gettext
+              use Gettext, backend: #{inspect(__CALLER__.module)}
           """,
           Macro.Env.stacktrace(__CALLER__)
         )


Test patch:
diff --git a/test/gettext_test.exs b/test/gettext_test.exs
index 0be1256..ec4bbc2 100644
--- a/test/gettext_test.exs
+++ b/test/gettext_test.exs
@@ -279,7 +279,27 @@ defmodule GettextTest do
         )
       end)
 
-    assert stderr =~ "defining a Gettext backend by calling"
-    assert stderr =~ "is deprecated"
+    expected_message = """
+    Defining a Gettext backend by calling:
+
+        use Gettext, otp_app: :my_app
+
+    is deprecated. To define a backend, call:
+
+        use Gettext.Backend, otp_app: :my_app
+
+    Then, replace importing your backend:
+
+        import DeprecatedWayOfDefiningBackend
+
+    with calling this in your module:
+
+        use Gettext, backend: DeprecatedWayOfDefiningBackend
+
+      nofile:1: DeprecatedWayOfDefiningBackend (module)
+
+    """
+
+    assert stderr =~ expected_message
   end
 end