Hi Andreas,

here you go:

-------------------------------------------------------------------------
namespace Application;

use Application\Listener\ApplicationListener;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;

class Module implements BootstrapListenerInterface
{
    public function onBootstrap(EventInterface $e)
    {
        // attach application listener
        $eventManager = $e->getApplication()->getEventManager();
        $eventManager->attachAggregate(new ApplicationListener());
    }
}

-------------------------------------------------------------------------
namespace Application\Listener;

use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\I18n\Translator\Translator;
use Zend\Mvc\MvcEvent;
use Zend\Validator\AbstractValidator;

class ApplicationListener implements ListenerAggregateInterface
{
    protected $listeners = array();

    public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach(
            MvcEvent::EVENT_DISPATCH,
            array($this, 'addValidatorTranslations'),
            100
        );
    }

    public function detach(EventManagerInterface $events)
    {
        foreach ($this->listeners as $index => $listener) {
            if ($events->detach($listener)) {
                unset($this->listeners[$index]);
            }
        }
    }

    public function addValidatorTranslations(EventInterface $e)
    {
        $baseDir = APPLICATION_ROOT . '/module/Application/language';

        $translator = Translator::factory(array(
            'locale'                    => 'de',
            'translation_file_patterns' => array(
                array(
                    'type'        => 'phpArray',
                    'base_dir'    => $baseDir,
                    'pattern'     => 'Zend_Validate.php',
                    'text_domain' => 'default',
                ),
            )
        ));

        AbstractValidator::setDefaultTranslator($translator);
    }
}

-------------------------------------------------------------------------

The APPLICATION_ROOT constant is set in my index.php to the path of the,
well, application root.

HTH,

Ralf

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to