diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index da60eeabb41c9..44cf1b99134b8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -1342,7 +1342,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder $defaultDir = $container->getParameterBag()->resolveValue($config['default_path']); foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) { if ($container->fileExists($dir = $bundle['path'].'/Resources/translations') || $container->fileExists($dir = $bundle['path'].'/translations')) { - $dirs[] = $dir; + $dirs[] = $transPaths[] = $dir; } else { $nonExistingDirs[] = $dir; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/translations/messages.en.yaml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/translations/messages.en.yaml new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 52a6ad6a4840f..215b318d5e44d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -1072,7 +1072,19 @@ public function testMessengerWithDisabledResetOnMessage() public function testTranslator() { - $container = $this->createContainerFromFile('full'); + require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php'; + + $container = $this->createContainerFromFile('full', [ + 'kernel.bundles' => [ + 'FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle', + 'TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle', + ], + 'kernel.bundles_metadata' => [ + 'FrameworkBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..'], + 'TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle'], + ], + ]); + $this->assertTrue($container->hasDefinition('translator.default'), '->registerTranslatorConfiguration() loads translation.php'); $this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator'); $options = $container->getDefinition('translator.default')->getArgument(4); @@ -1115,6 +1127,11 @@ public function testTranslator() '->registerTranslatorConfiguration() finds translation resources with dots in domain' ); $this->assertContains(strtr(__DIR__.'/translations/security.en.yaml', '/', \DIRECTORY_SEPARATOR), $files); + $this->assertContains( + strtr(__DIR__.'/Fixtures/TestBundle/Resources/translations/messages.en.yaml', '/', \DIRECTORY_SEPARATOR), + $files, + '->registerTranslatorConfiguration() finds translation resources within bundles' + ); $positionOverridingTranslationFile = array_search(strtr(realpath(__DIR__.'/translations/security.en.yaml'), '/', \DIRECTORY_SEPARATOR), $files); @@ -1140,7 +1157,38 @@ function ($directory) { $this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator'); - $this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]); + $this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][4]); + + $transPaths = $container->getDefinition('console.command.translation_extract')->getArgument(6); + + $ref = new \ReflectionClass(Validation::class); + $this->assertContains( + strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR), + $transPaths, + '->registerTranslatorConfiguration() finds Validator translation resources to extract' + ); + $ref = new \ReflectionClass(Form::class); + $this->assertContains( + strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR), + $transPaths, + '->registerTranslatorConfiguration() finds Form translation resources to extract' + ); + $ref = new \ReflectionClass(Security::class); + $this->assertContains( + strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR), + $transPaths, + '->registerTranslatorConfiguration() finds Security translation resources to extract' + ); + $this->assertContains( + strtr(__DIR__.'/Fixtures/translations', '/', \DIRECTORY_SEPARATOR), + $transPaths, + '->registerTranslatorConfiguration() finds translation resources in custom paths to extract' + ); + $this->assertContains( + strtr(__DIR__.'/Fixtures/TestBundle/Resources/translations', '/', \DIRECTORY_SEPARATOR), + $transPaths, + '->registerTranslatorConfiguration() finds translation resources with in bundles to extract' + ); } public function testTranslatorMultipleFallbacks()