0
votes

I have custom message like this:

'options' => array(
    'min' => $min,
    'max' => $date->format('Y-m-d'),
    'inclusive' => true,
    'messages' => array(
        Between::NOT_BETWEEN => "The input is not between '%min%' and '%max%', inclusively",
    ),
),

I put this string in .po file and generate .mo, but message won't translate. For all other messages without variables it's working fine.

2

2 Answers

0
votes

It would have been nice, if you had given more explanation. Generally If string contains variables , You have to replace them with string formatters.

In your case msgid "The input is not between %s and %s"

I hope it should solve your problem.

0
votes

You can read in the ZF2 official documentation on how to do this.

The translation files for validators are located at /resources/languages. You should simply attach a translator to Zend\Validator\AbstractValidator using these resource files or in your case your own file for your custom messages.

$validator->setDefaultTranslator($translator);

EDIT

I misinterpreted your question, here an edit

Can you not translate the message before binding the variables like this:

$translator = ...translator...

'options' => array(
    'min' => $min,
    'max' => $date->format('Y-m-d'),
    'inclusive' => true,
    'messages' => array(
        Between::NOT_BETWEEN => $translator->translate(
            "The input is not between '%min%' and '%max%', inclusively"
        ),
    ),
),