Localization of validation messages

26 views
Skip to first unread message

Miguel Prz

unread,
Feb 18, 2018, 3:13:38 AM2/18/18
to Mojolicious
I am using Mojolicious::Validator::Validation in my Web app.
I have to translate the error messages, for example "required" should be "requerido" (spanish).
How can I do this?


Jan Henning Thorsen

unread,
Feb 18, 2018, 8:32:29 AM2/18/18
to Mojolicious
I've tried to be clever about this many times, and it always ends up in a huge mess. So instead of trying to detect the exact issue, I will rather just tell the user what needs to be done:

% if (validation->has_error('username') {
  <p class="help"><%=l 'You need to fill in a username, which needs to be...' %></p>
% }

The "<%=l' part is the same as <%= l('you need to...') %>, I just like to write it a "funny" way. The l() helper needs to do the actual translation for you, as you would with any other string in your application.

sri

unread,
Feb 18, 2018, 10:47:04 AM2/18/18
to Mojolicious
I've tried to be clever about this many times, and it always ends up in a huge mess. So instead of trying to detect the exact issue, I will rather just tell the user what needs to be done:

% if (validation->has_error('username') {
  <p class="help"><%=l 'You need to fill in a username, which needs to be...' %></p>
% }

This is the correct solution.

--
sebastian 
Reply all
Reply to author
Forward
0 new messages