Reputation: 846
I struggle to set a default language for the error messages (displayed when trying to submit a invalid form) in Zend 2. I've downloaded the code from the quick start tutorial and added the following lines to ..module\Album\config\module.config.php:
//[...]
'translator' => array(
'locale' => 'de_DE',
'translation_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
and
$translator = $this->getServiceLocator()->get('translator');
$translator->setLocale('de_DE');
in my controller. Neither seems to work. There are some translations in ...\vendor\zendframework\zendframework\resources\languages. I don't have the Intl PHP extension installed, but I hope very much that the translation will work without this extension.
Thanks for your help,
Andreas
Upvotes: 1
Views: 736
Reputation: 846
After some research, it appears that the Intl PHP Extension is really required. With the Intl Extension, you can set the default Translator to the abstract validator. From the docs:
$translator = new Zend\I18n\Translator\Translator();
$translator->addTranslationFile(
'phpArray',
'resources/languages/en.php',
'default',
'en_US'
);
Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
Upvotes: 1