Schema internationalization/localization

I have translated some custom error message in a schema, it just works, no problem here.
But to do that I have imported import MyappWeb.Gettext into the schema which is inside Myapp module. Importing something from MyappWeb into Myapp makes me feel that I am doing something wrong. More generally gettext is not in Myapp so should I even internationalize messages inside the schema?

Is there another way to do the translation importing gettext from MyappWeb or any other place into Myapp? Or should I try report the error somehow that doesn’t need to be internationalized inside schema? how?
Or maybe it is just OK to do the internationalization inside a schema.

It seems it is not OK at all. If I do the internationalization inside schema, then I need to import gettext into tests. It was not needed for other validation errors that Phoenix sets itself. I think I need to find another way.

OK, I found a way. I added msgid and msgstr to errors.pot file. Then I ran mix gettext.merge priv/gettext to update the .po files. And there I added the translated string.
There is file views/error_helpers.ex I think it is doing the translation.

4 Likes