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__) ) 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