ZF3 validator php file not working

I translate validation errors with a PHP file and that works fine for eg:

 "Invalid type given. String expected" => "Verkeer type opgegevens er wordt tekst verwacht",

But when using a wildcard it does not work:

 "The input is less than %min% characters long" => "De input is minder dan %min% karakters",

What is wrong?

I use this settup:


 'service_manager' => array(
    'aliases' => array(
        'translator' => 'MvcTranslator',


'translator' => [
    'locale' => 'nl_NL',
    'translation_file_patterns' => [
            'type' => 'phparray',
            'base_dir' => 'module/Application/lang',
            'pattern' => '%s.php',



return [
// Zend\Authentication\Validator\Authentication
"Invalid identity" => "Invalid identity",
"Identity is ambiguous" => "Identity is ambiguous",
"Invalid password" => "Invalid password",
"Authentication failed" => "Authentication failed",
// Zend\Validator\EmailAddress
"Invalid type given. String expected" => "Invalid type given. String expected",
"The input is not a valid email address. Use the basic format local-part@hostname" => "The input is not a valid email address. Use the basic format local-part@hostname",
"'%hostname%' is not a valid hostname for the email address" => "'%hostname%' is not a valid hostname for the email address",


Vallidator in Form

    'name'     => 'naam',
    'required' => true,
    'filters'  => [
       ['name' => 'StringTrim'],
       ['name' => 'StripTags'],
       ['name' => 'StripNewlines'],
    'validators' => [
        'name' => 'StringLength',
          'options' => [
            'min' => 3,
            'max' => 128

Hi @Jilco,
unfortunately, in your description the explanation of your procedure is missing. Therefore here are two examples.

Example 1

$validator = new Laminas\Validator\StringLength(['min' => 6]);
    'De input is minder dan %min% karakters',



array(1) {
  'stringLengthTooShort' =>
  string(34) "De input is minder dan 6 karakters"

Example 2

This example uses laminas-i18n-resources and laminas-mvc-i18n where are all messages already translated:

$translator = new Laminas\I18n\Translator\Translator();
    . '/vendor/laminas/laminas-i18n-resources/languages/nl/Laminas_Validate.php'
$mvcTranslator = new Laminas\Mvc\I18n\Translator($translator);

$validator     = new Laminas\Validator\StringLength(['min' => 6]);



array(1) {
  'stringLengthTooShort' =>
  string(36) "De input is minder dan 6 tekens lang"

I hope this helps otherwise please provide a code example which allows to reproduce your problem.

I added the code example, thanks in advance!

Does a translation work at all or only the messages without placeholders?

New problem , after

composer require laminas/laminas-mvc-i18n

My content is gone! Layout loads as it should, but content part is gone

<?= $this->content ?>

Something with the renaming i think, please help…

Please note this is a different problem then the translation of validator messages.
Follow the migration guide and if you still have problems, please open new thread for this.


I did the migration part this morning with succes :slight_smile:

Is there a possibility to use the migration file as a service or something, so that i don’t have to rebuild al te vallidators?

Stil no succes with the wildcards, normal translation is working but:

 "The input is not less than '%max%'" => "De input is niet minder dan '%max%'"

Is not translating :frowning:

Does it works with the usage of the related class constant?

    Laminas\Validator\LessThan::NOT_LESS => "De input is niet minder dan '%max%'",