We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



26.3k

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;
      }
  }

}
  • If you are asking about model messages, there is an issue with Phalcon's default notNullValidators. It is described here https://forum.phalcon.io/discussion/2547/give-custom-model-validation-priority.

  • I am suggesting you using gettext extension for translations. It has the best performance and supports plurals. Plurals are important if you are interested in generating high quality translations.