Commit 42f199cc authored by Fabien Potencier's avatar Fabien Potencier

Merge branch '1.3'

* 1.3:
  fixed translation registration for the validators
parents 6d56243b 53f0df43
...@@ -27,7 +27,7 @@ Changelog ...@@ -27,7 +27,7 @@ Changelog
1.3.4 (2015-XX-XX) 1.3.4 (2015-XX-XX)
------------------ ------------------
* n/a * fixed translation registration for the validators
1.3.3 (2015-09-08) 1.3.3 (2015-09-08)
------------------ ------------------
......
...@@ -74,14 +74,6 @@ class FormServiceProvider implements ServiceProviderInterface ...@@ -74,14 +74,6 @@ class FormServiceProvider implements ServiceProviderInterface
if (isset($app['validator'])) { if (isset($app['validator'])) {
$extensions[] = new FormValidatorExtension($app['validator']); $extensions[] = new FormValidatorExtension($app['validator']);
if (isset($app['translator']) && method_exists($app['translator'], 'addResource')) {
$r = new \ReflectionClass('Symfony\Component\Form\Form');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$app['translator']->addResource('xliff', $file, $app['locale'], 'validators');
}
}
} }
return $extensions; return $extensions;
......
...@@ -40,6 +40,22 @@ class TranslationServiceProvider implements ServiceProviderInterface, EventListe ...@@ -40,6 +40,22 @@ class TranslationServiceProvider implements ServiceProviderInterface, EventListe
$translator->addLoader('array', new ArrayLoader()); $translator->addLoader('array', new ArrayLoader());
$translator->addLoader('xliff', new XliffFileLoader()); $translator->addLoader('xliff', new XliffFileLoader());
if (isset($app['validator'])) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$translator->addResource('xliff', $file, $app['locale'], 'validators');
}
}
if (isset($app['form.factory'])) {
$r = new \ReflectionClass('Symfony\Component\Form\Form');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$translator->addResource('xliff', $file, $app['locale'], 'validators');
}
}
// Register default resources // Register default resources
foreach ($app['translator.resources'] as $resource) { foreach ($app['translator.resources'] as $resource) {
$translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]); $translator->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
......
...@@ -29,20 +29,6 @@ class ValidatorServiceProvider implements ServiceProviderInterface ...@@ -29,20 +29,6 @@ class ValidatorServiceProvider implements ServiceProviderInterface
public function register(Container $app) public function register(Container $app)
{ {
$app['validator'] = function ($app) { $app['validator'] = function ($app) {
if (isset($app['translator'])) {
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
if (file_exists($file)) {
$app->extend('translator.resources', function ($resources, $app) use ($file) {
$resources = array_merge(array(
array('xliff', $file, $app['locale'], 'validators'),
), $resources);
return $resources;
});
}
}
return $app['validator.builder']->getValidator(); return $app['validator.builder']->getValidator();
}; };
......
...@@ -146,7 +146,10 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -146,7 +146,10 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testAddResource() /**
* @dataProvider getAddResourceData
*/
public function testAddResource($registerValidatorFirst)
{ {
$app = new Application(); $app = new Application();
$app['locale'] = 'fr'; $app['locale'] = 'fr';
...@@ -159,11 +162,18 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -159,11 +162,18 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
return $translator; return $translator;
}); });
if ($registerValidatorFirst) {
$app['validator']; $app['validator'];
}
$this->assertEquals('Pas vide', $app['translator']->trans('This value should not be blank.', array(), 'validators', 'fr')); $this->assertEquals('Pas vide', $app['translator']->trans('This value should not be blank.', array(), 'validators', 'fr'));
} }
public function getAddResourceData()
{
return array(array(false), array(true));
}
public function testAddResourceAlternate() public function testAddResourceAlternate()
{ {
$app = new Application(); $app = new Application();
......
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