Custom Ecto Validation Messages and i18n

329 views
Skip to first unread message

Jared Lewis

unread,
May 28, 2015, 2:49:05 AM5/28/15
to phoeni...@googlegroups.com
Hey Guys,

So, I'm using ecto with Phoenix and it seems the built-in Ecto validation messages ("can't be blank," etc...) are hard coded into Ecto. What are people's opinions as to the best way to go about customizing these messages?

Also, it seems that previously Phoenix came with an i18n library, Linguist, but now that it has been removed as a dependency. Is Linguist still a good way to handle i18n, or was it removed to make way for other approaches? I couldn't find much about i18n phoenix apps documentation or otherwise, so any input would be much appreciated.

Many thanks in advance!

Best,

Jared

Jared Lewis

unread,
May 28, 2015, 3:41:51 AM5/28/15
to phoeni...@googlegroups.com
Further input of course still welcome, but just for everyone's benefit, in #elixir-lang tmjoen noted ecto would get gettext integration in the next release, but in the meantime one could just match on the English strings: https://gist.github.com/tmjoen/456b2f7425d6990c7515

Steve Domin

unread,
May 28, 2015, 6:39:09 AM5/28/15
to phoeni...@googlegroups.com
Hi Jared,

With the built-in predicates you can pass a "message" option to customize the error message (http://hexdocs.pm/ecto/0.2.5/Ecto.Validator.Predicates.html)

Here's an example from the doc:

validate user,
         name
: present(),
          age
: present(message: "must be present")

Here's the repo for the upcoming gettext implementation: https://github.com/elixir-lang/gettext
Reply all
Reply to author
Forward
0 new messages