Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How can I translate/custom Phalcon's error messages?

Phalcon has some built in error messages, like this

    Value of field 'phone' doesn't match regular expression

I'm working on a multi-lang project, I want to make these error messages can be multi-lang, too.
Are these messages translatable?



16.6k

I am developing multi-lang project too.

  • When you define your validators you can pass your custom message values e.g.
<?php

use Phalcon\Mvc\Model\Validator\PresenceOf;

class Subscriptors extends Phalcon\Mvc\Model
{

  public function validation()
  {
      $this->validate(new PresenceOf(array(
          'field' => 'name',
          'message' => 'The name is required'
      )));
      if ($this->validationHasFailed() == true) {
          return false;
      }
  }

}