From 8278199af174d6e23cf2da8c091dc25305a97643 Mon Sep 17 00:00:00 2001 From: Kevin Verschaeve Date: Mon, 6 Nov 2017 10:33:08 +0100 Subject: [PATCH] [FrameworkBundle][Translations] Fix translation commands Search for translations also in the new translations dir at the project root Search for .yaml file as well as .yml --- .../Command/TranslationDebugCommand.php | 5 ++++- .../Command/TranslationUpdateCommand.php | 5 ++++- .../Resources/config/translation.xml | 2 +- .../Command/TranslationDebugCommandTest.php | 19 ++++++++++++++++--- .../Command/TranslationUpdateCommandTest.php | 8 +++++++- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 79b4234d81eb8..1152c7b3bcd9b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -113,7 +113,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $kernel = $this->getContainer()->get('kernel'); // Define Root Path to App folder - $transPaths = array($kernel->getRootDir().'/Resources/'); + $transPaths = array( + $kernel->getRootDir().'/Resources/', + $kernel->getProjectDir().'/', + ); // Override with provided Bundle info if (null !== $input->getArgument('bundle')) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index f18263f70ab53..5ac017b3c0ca6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -105,7 +105,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $kernel = $this->getContainer()->get('kernel'); // Define Root Path to App folder - $transPaths = array($kernel->getRootDir().'/Resources/'); + $transPaths = array( + $kernel->getRootDir().'/Resources/', + $kernel->getProjectDir().'/', + ); $currentName = 'app folder'; // Override with provided Bundle info diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index 5f98febda6304..a4b68d9ce5f78 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -33,7 +33,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php index 19c6d70156b19..b46f649b195b9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php @@ -65,7 +65,10 @@ public function testDebugDefaultDirectory() public function testDebugCustomDirectory() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->disableOriginalConstructor() + ->getMock(); + $kernel->expects($this->once()) ->method('getBundle') ->with($this->equalTo($this->translationDir)) @@ -83,7 +86,10 @@ public function testDebugCustomDirectory() */ public function testDebugInvalidDirectory() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->disableOriginalConstructor() + ->getMock(); + $kernel->expects($this->once()) ->method('getBundle') ->with($this->equalTo('dir')) @@ -152,7 +158,10 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar ); if (null === $kernel) { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->disableOriginalConstructor() + ->getMock(); + $kernel ->expects($this->any()) ->method('getBundle') @@ -167,6 +176,10 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar ->method('getRootDir') ->will($this->returnValue($this->translationDir)); + $kernel + ->method('getProjectDir') + ->will($this->returnValue($this->translationDir)); + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container ->expects($this->any()) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php index e845619d9a826..d0368a56f0c41 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php @@ -132,7 +132,9 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar ); if (null === $kernel) { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->disableOriginalConstructor() + ->getMock(); $kernel ->expects($this->any()) ->method('getBundle') @@ -147,6 +149,10 @@ private function getContainer($extractedMessages = array(), $loadedMessages = ar ->method('getRootDir') ->will($this->returnValue($this->translationDir)); + $kernel + ->method('getProjectDir') + ->will($this->returnValue($this->translationDir)); + $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container ->expects($this->any())