Advertisement
artuu

Zend2 - set default translator

Mar 31st, 2014
631
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Zend Framework (http://framework.zend.com/)
  4.  *
  5.  * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
  6.  * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  7.  * @license   http://framework.zend.com/license/new-bsd New BSD License
  8.  */
  9.  
  10. namespace Application;
  11.  
  12. use Zend\Mvc\ModuleRouteListener;
  13. use Zend\Mvc\MvcEvent;
  14. use Zend\Mvc;
  15. use Zend\Validator\AbstractValidator;
  16. use Zend\Mvc\I18n\Translator;
  17.  
  18.  
  19. class Module
  20. {
  21.     public function onBootstrap(MvcEvent $e)
  22.     {
  23.         $eventManager        = $e->getApplication()->getEventManager();
  24.         $moduleRouteListener = new ModuleRouteListener();
  25.         $moduleRouteListener->attach($eventManager);
  26.  
  27.         $translator = new Translator(new \Zend\I18n\Translator\Translator());
  28.         $translator->addTranslationFile(
  29.             'phpArray',
  30.             './vendor/zendframework/zendframework/resources/languages/pl/Zend_Validate.php'
  31.         );
  32.  
  33.         $translator->setLocale('pl_PL');
  34.         AbstractValidator::setDefaultTranslator(new Translator($translator));
  35.     }
  36.  
  37.     public function getConfig()
  38.     {
  39.         return include __DIR__ . '/config/module.config.php';
  40.     }
  41.  
  42.     public function getAutoloaderConfig()
  43.     {
  44.         return array(
  45.             'Zend\Loader\StandardAutoloader' => array(
  46.                 'namespaces' => array(
  47.                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
  48.                 ),
  49.             ),
  50.         );
  51.     }
  52. }
Advertisement
RAW Paste Data Copied
Advertisement