Commit 38d505a0 authored by Fabien Potencier's avatar Fabien Potencier

made form and validator translations aware of the current locale

parent 9674ce90
Changelog Changelog
========= =========
* **2012-06-16**: renamed ``request.default_locale`` to ``locale``
* **2012-06-16**: Removed the ``translator.loader`` service. See documentation * **2012-06-16**: Removed the ``translator.loader`` service. See documentation
for how to use XLIFF or YAML-based translation files. for how to use XLIFF or YAML-based translation files.
......
...@@ -85,7 +85,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -85,7 +85,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return $app['url_matcher']; return $app['url_matcher'];
}); });
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['logger'])); $dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['logger']));
$dispatcher->addSubscriber(new LocaleListener($app['request.default_locale'], $urlMatcher)); $dispatcher->addSubscriber(new LocaleListener($app['locale'], $urlMatcher));
return $dispatcher; return $dispatcher;
}); });
...@@ -147,8 +147,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -147,8 +147,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
} }
}); });
$this['request.default_locale'] = 'en';
$this['request_error'] = $this->protect(function () { $this['request_error'] = $this->protect(function () {
throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.'); throw new \RuntimeException('Accessed request service outside of request scope. Try moving that call to a before handler or controller.');
}); });
...@@ -159,6 +157,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -159,6 +157,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
$this['request.https_port'] = 443; $this['request.https_port'] = 443;
$this['debug'] = false; $this['debug'] = false;
$this['charset'] = 'UTF-8'; $this['charset'] = 'UTF-8';
$this['locale'] = 'en';
} }
/** /**
...@@ -537,6 +536,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe ...@@ -537,6 +536,8 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
$this['locale'] = $event->getRequest()->getLocale();
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->beforeDispatched = true; $this->beforeDispatched = true;
$this['dispatcher']->dispatch(SilexEvents::BEFORE, $event); $this['dispatcher']->dispatch(SilexEvents::BEFORE, $event);
......
...@@ -42,7 +42,7 @@ class FormServiceProvider implements ServiceProviderInterface ...@@ -42,7 +42,7 @@ class FormServiceProvider implements ServiceProviderInterface
if (isset($app['translator'])) { if (isset($app['translator'])) {
$r = new \ReflectionClass('Symfony\Component\Form\Form'); $r = new \ReflectionClass('Symfony\Component\Form\Form');
$app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.en.xlf', 'en', 'validators'); $app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf', $app['locale'], 'validators');
} }
} }
......
...@@ -28,8 +28,6 @@ class TranslationServiceProvider implements ServiceProviderInterface ...@@ -28,8 +28,6 @@ class TranslationServiceProvider implements ServiceProviderInterface
{ {
public function register(Application $app) public function register(Application $app)
{ {
$app['locale'] = 'en';
$app['translator'] = $app->share(function () use ($app) { $app['translator'] = $app->share(function () use ($app) {
$translator = new Translator($app['locale'], $app['translator.message_selector']); $translator = new Translator($app['locale'], $app['translator.message_selector']);
......
...@@ -31,7 +31,7 @@ class ValidatorServiceProvider implements ServiceProviderInterface ...@@ -31,7 +31,7 @@ class ValidatorServiceProvider implements ServiceProviderInterface
$app['validator'] = $app->share(function () use ($app) { $app['validator'] = $app->share(function () use ($app) {
if (isset($app['translator'])) { if (isset($app['translator'])) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validator'); $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
$app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.en.xlf', 'en', 'validators'); $app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf', $app['locale'], 'validators');
} }
return new Validator( return new Validator(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment