I have a local app
A which is a dependency of a Phoenix project
A has translations, from
iex(1)> import A.Gettext
iex(2)> Gettext.put_locale(A.Gettext, "de")
iex(3)> dgettext("a", "Log in")
If I try to get the same translation from
B, I got the wrong locale:
iex(4)> import A.Gettext
iex(5)> Gettext.put_locale(A.Gettext, "de")
iex(6)> dgettext("a", "Log in")
What am I missing here?
Two ideas to investigate come to my mind
priv/ translations directory is maybe being compiled to a non-existent path when you load the local dependency from
B, or not being compiled at all. Try
B and if it returns
 then it can’t find your translations directory.
If you have any gettext config in
a/config/*.exs then it is not available in
B and you’ll have to set that config in
b/config/*.exs as well.
I had a little time to test this out. If you are pulling in
A as a local path dependency then your
priv translations directory should be compiled along with the dependency into
b/_build/dev/lib/a/priv/path_to_locales/. If it’s not there, then my theory is that you compiled your PO files in
mix compile.gettext) after the last compilation of
A as a dependency in
mix do deps.clean a, deps.update a, deps.compile from the
B directory should fix that, and then it all should work.
You probably need to use
put_locale("de") rather than
put_locale(A.Gettext, "de"), which will set the locale for all Gettext backends in the current process, rather than just the one from
A: Gettext — gettext v0.19.1
That is indeed the reason it was not working.
Thank you very much