php - Translate Zend Form Validation Error Messages?

396

I have application that runs with different languages. The custom labels, header$this->translate('message') are working perfectly with any problem. I just face problem with translating zend error Message form. Here is what I added it inmodule.config.php. Could any one help me to display error message form in different languages.

'translator' => array(
    'locale' => 'pl',
    'translation_file_patterns' => array(
        array(
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ),
        array(
            'type' => 'phpArray',
            'base_dir' => 'vendor/zendframework/zend-i18n-resources/languages',
            'pattern' => '%s/Zend_Captcha.php',
            'text_domain' => 'formvalidation',
        ),
        array(
            'type' => 'phpArray',
            'base_dir' => 'vendor/zendframework/zend-i18n-resources/languages',
            'pattern' => '%s/Zend_Validate.php',
            'text_domain' => 'formvalidation',
        ),
    ),
),
275

Answer

Solution:

This is how I do it within the getInputFilter form function. This way I can retrieve the string in Poedit and proceed with the translations:

public function getInputFilter() {
if (!$this->filter) {
    $inputFilter = new InputFilter();
    $factory = new InputFactory ();

    $inputFilter->add($factory->createInput(array(
        'name' => 'email',
        'filters' => array(
            array(
                'name' => 'StripTags'
                ),
            array(
                'name' => 'StringTrim'
                )
            ),
        'validators' => array(
            array(
                'name' => 'EmailAddress',
                'options' => array(
                    'messages' => array(
                        'emailAddressInvalidFormat' => _('Email address format is not invalid')
                        )
                    )
                ),
            array(
                'name' => 'NotEmpty',
                'options' => array(
                    'messages' => array(
                        'isEmpty' => _('Email address is required')
                        )
                    )
                ),
            array(
                'name' => 'StringLength',
                'options' => array(
                    'min'=>6,
                    'max'=>128,
                    'messages' => array(
                        \Zend\Validator\StringLength::TOO_LONG => _('Invalid length for this field')
                        )
                    )
                )
            )
        )));
        $this->filter = $inputFilter;
}
return $this->filter;
}

People are also looking for solutions to the problem: php - Cannot set FK constrains in MySQL

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.