8000 [FrameworkBundle] Deprecate support for legacy directories in Translation comands by chalasr · Pull Request #28892 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Deprecate support for legacy directories in Translation comands #28892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADE-4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ FrameworkBundle
set the "APP_DEBUG" environment variable to "0" instead.
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter.
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated.

Messenger
---------
Expand Down
1 change: 1 addition & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ FrameworkBundle
set the "APP_DEBUG" environment variable to "0" instead.
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been removed, use the `trans()` one instead with a `%count%` parameter.
* Removed support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been removed.

HttpFoundation
--------------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CHANGELOG
* Deprecated `CachePoolPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPass` instead.
* Deprecated `CachePoolPrunerPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass` instead.
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
* Deprecated support for the legacy directory structure in `translation:update` and `debug:translation` commands.

4.1.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');

// Define Root Paths
$transPaths = array($rootDir.'/Resources/translations');
$transPaths = array();
if (is_dir($dir = $rootDir.'/Resources/translations')) {
if ($dir !== $this->defaultTransPath) {
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
}
$transPaths[] = $dir;
}
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = array($rootDir.'/Resources/views');
$viewsPaths = array();
if (is_dir($dir = $rootDir.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
}
$viewsPaths[] = $dir;
}
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
Expand All @@ -146,35 +160,60 @@ protected function execute(InputInterface $input, OutputInterface $output)
$bundle = $kernel->getBundle($input->getArgument('bundle'));
$transPaths = array($bundle->getPath().'/Resources/translations');
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
$transPaths[] = $this->defaultTransPath;
}
10000 if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
$transPaths[] = $dir;
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $dir, $bundle->getName());
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : sprintf('configure and use "framework.translator.default_path" instead.', $bundle->getName())), E_USER_DEPRECATED);
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
$viewsPaths = array($bundle->getPath().'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
$viewsPaths[] = $this->defaultViewsPath;
}
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
$viewsPaths[] = $dir;
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $dir);
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : sprintf('configure and use "twig.default_path" instead.', $bundle->getName())), E_USER_DEPRECATED);
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
$path = $input->getArgument('bundle');

$transPaths = array($path.'/translations');
if (is_dir($dir = $path.'/Resources/translations')) {
if ($dir !== $this->defaultTransPath) {
@trigger_error(sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, use the "%s" directory instead.', $dir, $path.'/translations'), E_USER_DEPRECATED);
}
$transPaths[] = $dir;
}

if (!is_dir($transPaths[0])) {
$viewsPaths = array($path.'/templates');
if (is_dir($dir = $path.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
@trigger_error(sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, use the "%s" directory instead.', $dir, $path.'/templates'), E_USER_DEPRECATED);
}
$viewsPaths[] = $dir;
}

if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
}
}
} elseif ($input->getOption('all')) {
foreach ($kernel->getBundles() as $bundle) {
$transPaths[] = $bundle->getPath().'/Resources/translations';
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
$transPaths[] = $deprecatedPath;
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
$viewsPaths[] = $bundle->getPath().'/Resources/views';
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
$viewsPaths[] = array($bundle->getPath().'/Resources/views');
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
$viewsPaths[] = $deprecatedPath;
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : sprintf('configure and use "twig.default_path" instead.', $bundle->getName())), E_USER_DEPRECATED);
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
}
}

Expand Down
9E7A
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');

// Define Root Paths
$transPaths = array($rootDir.'/Resources/translations');
$transPaths = array();
if (is_dir($dir = $rootDir.'/Resources/translations')) {
if ($dir !== $this->defaultTransPath) {
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
}
$transPaths[] = $dir;
}
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = array($rootDir.'/Resources/views');
$viewsPaths = array();
if (is_dir($dir = $rootDir.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
}
$viewsPaths[] = $dir;
}
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
Expand All @@ -137,22 +151,44 @@ protected function execute(InputInterface $input, OutputInterface $output)
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
$transPaths = array($foundBundle->getPath().'/Resources/translations');
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
$transPaths[] = $this->defaultTransPath;
}
if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName()))) {
$transPaths[] = $dir;
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
}
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName());
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
$viewsPaths[] = $this->defaultViewsPath;
}
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName()))) {
$viewsPaths[] = $dir;
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : sprintf('configure and use "twig.default_path" instead.', $foundBundle->getName())), E_USER_DEPRECATED);
}
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName());
$currentName = $foundBundle->getName();
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
$currentName = $transPaths[0];
$path = $input->getArgument('bundle');

$transPaths = array($path.'/translations');
if (is_dir($dir = $path.'/Resources/translations')) {
if ($dir !== $this->defaultTransPath) {
@trigger_error(sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, use the "%s" directory instead.', $dir, $path.'/translations'), E_USER_DEPRECATED);
}
$transPaths[] = $dir;
}

$viewsPaths = array($path.'/templates');
if (is_dir($dir = $path.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
@trigger_error(sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, use the "%s" directory instead.', $dir, $path.'/templates'), E_USER_DEPRECATED);
}
$viewsPaths[] = $dir;
}

if (!is_dir($transPaths[0])) {
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ public function testDebugDefaultDirectory()
$this->assertRegExp('/unused/', $tester->getDisplay());
}

/**
* @group legacy
* @expectedDeprecation Storing translations in the "%ssf_translation%s/Resources/t F438 ranslations" directory is deprecated since Symfony 4.2, use the "%ssf_translation%s/translations" directory instead.
* @expectedDeprecation Storing templates in the "%ssf_translation%s/Resources/views" directory is deprecated since Symfony 4.2, use the "%ssf_translation%s/templates" directory instead.
*/
public function testDebugLegacyDefaultDirectory()
{
$this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views');

$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'));
$tester->execute(array('locale' => 'en'));

$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertRegExp('/unused/', $tester->getDisplay());
}

public function testDebugDefaultRootDirectory()
{
$this->fs->remove($this->translationDir);
Expand All @@ -82,14 +99,16 @@ public function testDebugDefaultRootDirectory()

public function testDebugCustomDirectory()
{
$this->fs->mkdir($this->translationDir.'/customDir/translations');
$this->fs->mkdir($this->translationDir.'/customDir/templates');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
$kernel->expects($this->once())
->method('getBundle')
->with($this->equalTo($this->translationDir))
->with($this->equalTo($this->translationDir.'/customDir'))
->willThrowException(new \InvalidArgumentException());

$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'), $kernel);
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir));
$tester->execute(array('locale' => 'en', 'bundle' => $this->translationDir.'/customDir'));

$this->assertRegExp('/missing/', $tester->getDisplay());
$this->assertRegExp('/unused/', $tester->getDisplay());
Expand All @@ -114,8 +133,6 @@ protected function setUp()
{
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views');
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpKernel;

Expand Down Expand Up @@ -80,6 +81,23 @@ public function testWriteMessagesInRootDirectory()
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
}

/**
* @group legacy
* @expectedDeprecation Storing translations in the "%ssf_translation%s/Resources/translations" directory is deprecated since Symfony 4.2, use the "%ssf_translation%s/translations" directory instead.
* @expectedDeprecation Storing templates in the "%ssf_translation%s/Resources/views" directory is deprecated since Sy C6EC mfony 4.2, use the "%ssf_translation%s/templates" directory instead.
*/
public function testWriteMessagesInLegacyRootDirectory()
{
$this->fs->remove($this->translationDir);
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views');

$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')));
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--force' => true));
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
}

public function testWriteMessagesForSpecificDomain()
{
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar')));
Expand All @@ -91,8 +109,6 @@ protected function setUp()
{
$this->fs = new Filesystem();
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
$this->fs->mkdir($this->translationDir.'/Resources/translations');
$this->fs->mkdir($this->translationDir.'/Resources/views');
$this->fs->mkdir($this->translationDir.'/translations');
$this->fs->mkdir($this->translationDir.'/templates');
}
Expand Down Expand Up @@ -174,10 +190,12 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
->method('getBundles')
->will($this->returnValue(array()));

$container = new Container();
$container->setParameter('kernel.root_dir', $this->translationDir);
$kernel
->expects($this->any())
->method('getContainer')
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock()));
->will($this->returnValue($container));

$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates');

Expand Down
0