Search code examples
zend-formzend-framework2zend-translate

Zend Framework 2 - Form translate


i got a question regarding the Zend Framework 2 Form translate. Right now i cannot translate form error messages from english to italian (my language).

I tried to set up the module.config.php as follow:

//...
'translator' => array(
    'locale' => 'it_IT',
    'translation_file_patterns' => array(
        array(
            'type' => 'phparray',
            'base_dir' => __DIR__. '/../language/form_errors',
            'pattern' => '%s.php'
        )
    ),
),

And the file is currently loaded in the Translator class. The problem is: even if i write the index (or the message) of the form error, it will not translate the form message.

return array(
'Skeleton Application' => 'Applicazione Scheletro',
"IS_EMPTY" => 'Il valore non può essere vuoto'
);

However, if i use the $translator->translate('Skeleton Application') it works like a charm...any tips ?

Thanks in advice..


Solution

  • That's because you need to translate the english error messages, this is not "IS_EMPTY" but something like "This input is required and can't be empty".

    I'd recommend you to use the gettext translation. It's still pretty fast but provides you some powerful tools to translate and fetch translation strings from the source (for instance PoEdit).