diff --git a/core/lib/Thelia/Config/Resources/translation.xml b/core/lib/Thelia/Config/Resources/translation.xml index 2fdef3882..c2ef4e8b5 100644 --- a/core/lib/Thelia/Config/Resources/translation.xml +++ b/core/lib/Thelia/Config/Resources/translation.xml @@ -57,6 +57,11 @@ + + + + + diff --git a/core/lib/Thelia/Core/EventListener/RequestListener.php b/core/lib/Thelia/Core/EventListener/RequestListener.php new file mode 100644 index 000000000..4b9c242b4 --- /dev/null +++ b/core/lib/Thelia/Core/EventListener/RequestListener.php @@ -0,0 +1,94 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Core\EventListener; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\KernelEvents; +use Thelia\Core\Translation\Translator; + + +/** + * Class RequestListener + * @package Thelia\Core\EventListener + * @author manuel raynaud + */ +class RequestListener implements EventSubscriberInterface +{ + protected $translator; + + public function __construct(Translator $translator) + { + $this->translator = $translator; + } + + public function registerValidatorTranslator(GetResponseEvent $event) + { + $request = $event->getRequest(); + $lang = $request->getSession()->getLang(); + $vendorDir = THELIA_ROOT . "/core/vendor"; + $vendorFormDir = $vendorDir . '/symfony/form/Symfony/Component/Form'; + $vendorValidatorDir = + $vendorDir . '/symfony/validator/Symfony/Component/Validator'; + + $this->translator->addResource( + 'xlf', + sprintf($vendorFormDir . '/Resources/translations/validators.%s.xlf', $lang->getCode()), + $lang->getLocale(), + 'validators' + ); + $this->translator->addResource( + 'xlf', + sprintf($vendorValidatorDir . '/Resources/translations/validators.%s.xlf', $lang->getCode()), + $lang->getLocale(), + 'validators' + ); + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + KernelEvents::REQUEST => array("registerValidatorTranslator", 128) + ); + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index 137513261..8dff18cfc 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -71,7 +71,6 @@ abstract class BaseForm public function __construct(Request $request, $type= "form", $data = array(), $options = array()) { $this->request = $request; - $lang = $request->getSession()->getLang(); $validator = Validation::createValidatorBuilder(); @@ -94,25 +93,6 @@ abstract class BaseForm $translator = Translator::getInstance(); - $vendorDir = THELIA_ROOT . "/core/vendor"; - $vendorFormDir = $vendorDir . '/symfony/form/Symfony/Component/Form'; - $vendorValidatorDir = - $vendorDir . '/symfony/validator/Symfony/Component/Validator'; - - $translator->addResource( - 'xlf', - sprintf($vendorFormDir . '/Resources/translations/validators.%s.xlf', $lang->getCode()), - $lang->getLocale(), - 'validators' - ); - $translator->addResource( - 'xlf', - sprintf($vendorValidatorDir . '/Resources/translations/validators.%s.xlf', $lang->getCode()), - $lang->getLocale(), - 'validators' - ); - - $validator ->setTranslationDomain('validators') ->setTranslator($translator);