1

I've read and studied these links without result :

http://framework.zend.com/manual/2.2/en/modules/zend.validator.messages.html

ZF2 Use non-en default locale for default Validator messages

So, here is my code. I've just started from ZendSkeletonApplication.

Here is onBootstrap() in Class Module :

public function onBootstrap(MvcEvent $e)
{
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);


    \Locale ::setDefault('fr_FR');

    $translator = new \Zend\Mvc\I18n\Translator();
    $translator->addTranslationFile(
            'phpArray',
            'resources/languages/fr/Zend_Validate.php',
            __NAMESPACE__,
             'fr_FR'
    );
    \Zend\Validator\AbstractValidator::setDefaultTranslator($translator);
}

Here is a part of module.config.php :

'service_manager' => array(
    'abstract_factories' => array(
        'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
        'Zend\Log\LoggerAbstractServiceFactory',
    ),
    'aliases' => array(
        'translator' => 'MvcTranslator',
    ),
),
'translator' => array(
    'locale' => 'fr_FR',
    'translation_file_patterns' => array(
        array(
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ),
    ),
),

And all validation messages are in english! Zend_Validate.php is in vendor/zendframework/zendframework/resources/languages/fr/

Where is my error ?

Community
  • 1
  • 1

2 Answers2

0

I had the same problem.

I used your code in my onBootstrap Module.php method of namespace Application.

Though it doesn't work where I was testing, searching the related topic here, at stack overflow.com, I found this code that uses 'default' and not NAMESPACE as the third parameter $textMode.

Then, when I changed my NAMESPACE constant by 'default', a path error of file happened.

I don't know how fix this and I didn't find how to do it yet. But, I think that you can use the same solution that I used, that is, putting the full path of resources' directory.

Example code (default): Zend Framework 2 - Translate Standard Form Validation and Error messages

Method's doc here (addTranslationFile): http://framework.zend.com/apidoc/2.2/classes/Zend.Mvc.I18n.Translator.html

Community
  • 1
  • 1
mold
  • 1,012
  • 7
  • 17
  • Hi, I've just seen your answer. Since 2 months, I worked elsewhere! Your solution is working : thank you very much ! – user2670354 Nov 18 '13 at 22:57
0

Put in your module.config.php

'translator' => [
    'locale' => 'fr_FR',
    'translation_file_patterns' => [
        [
            'type'     => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => '%s.mo',
        ], [
            'type'     => 'phpArray',
            'base_dir' => './vendor/zendframework/zendframework/resources/languages',
            'pattern'  => '%.2s/Zend_Validate.php',
        ],
    ],
],
B.Asselin
  • 978
  • 10
  • 19