Permalink
Browse files

made form and validator translations aware of the current locale

  • Loading branch information...
1 parent 9674ce9 commit 38d505a05f0cab41cded07cda10df46e9f04084f @fabpot committed Jun 16, 2012
View
@@ -1,6 +1,8 @@
Changelog
=========
+* **2012-06-16**: renamed ``request.default_locale`` to ``locale``
+
* **2012-06-16**: Removed the ``translator.loader`` service. See documentation
for how to use XLIFF or YAML-based translation files.
@@ -85,7 +85,7 @@ public function __construct()
return $app['url_matcher'];
});
$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;
});
@@ -147,8 +147,6 @@ public function __construct()
}
});
- $this['request.default_locale'] = 'en';
-
$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.');
});
@@ -159,6 +157,7 @@ public function __construct()
$this['request.https_port'] = 443;
$this['debug'] = false;
$this['charset'] = 'UTF-8';
+ $this['locale'] = 'en';
}
/**
@@ -537,6 +536,8 @@ public function onEarlyKernelRequest(GetResponseEvent $event)
*/
public function onKernelRequest(GetResponseEvent $event)
{
+ $this['locale'] = $event->getRequest()->getLocale();
+
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$this->beforeDispatched = true;
$this['dispatcher']->dispatch(SilexEvents::BEFORE, $event);
@@ -42,7 +42,7 @@ public function register(Application $app)
if (isset($app['translator'])) {
$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
{
public function register(Application $app)
{
- $app['locale'] = 'en';
-
$app['translator'] = $app->share(function () use ($app) {
$translator = new Translator($app['locale'], $app['translator.message_selector']);
@@ -31,7 +31,7 @@ public function register(Application $app)
$app['validator'] = $app->share(function () use ($app) {
if (isset($app['translator'])) {
$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(

0 comments on commit 38d505a

Please sign in to comment.