10000 [FrameworkBundle] Removed capability to load/debug/update legacy translation directories by yceruto · Pull Request #31668 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Removed capability to load/debug/update legacy translation directories #31668

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
May 29, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$domain = $input->getOption('domain');
/** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel();
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');

// Define Root Paths
$transPaths = $this->transPaths;
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 = $this->viewsPaths;
if (is_dir($dir = $rootDir.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
$notice = sprintf('Loading Twig templates from 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 @@ -166,39 +151,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
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) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
}
$viewsPaths = [$bundle->getPath().'/Resources/views'];
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
}
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
$viewsPaths[] = $dir;
$notice = sprintf('Loading Twig templates for "%s" from 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) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
}
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$path = $input->getArgument('bundle');

$transPaths = [$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 = [$path.'/templates'];
if (is_dir($dir = $path.'/Resources/views')) {
if ($dir !== $this->defaultViewsPath) {
@trigger_error(sprintf('Loading Twig templates from 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]));
Expand All @@ -207,17 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} elseif ($input->getOption('all')) {
foreach ($kernel->getBundles() as $bundle) {
$transPaths[] = $bundle->getPath().'/Resources/translations';
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);
}
$viewsPaths[] = $bundle->getPath().'/Resources/views';
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
$viewsPaths[] = $deprecatedPath;
$notice = sprintf('Loading Twig templates for "%s" from 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) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
/** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel();
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');

// Define Root Paths
$transPaths = $this->transPaths;
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 = $this->viewsPaths;
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 @@ -158,40 +143,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($this->defaultTransPath) {
$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);
}
$viewsPaths = [$foundBundle->getPath().'/Resources/views'];
if ($this->defaultViewsPath) {
$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) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
}
$currentName = $foundBundle->getName();
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$path = $input->getArgument('bundle');

$transPaths = [$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 = [$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]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,19 +1116,12 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$dirs[] = $transPaths[] = \dirname(\dirname($r->getFileName())).'/Resources/translations';
}
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
$rootDir = $container->getParameter('kernel.root_dir');
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
if (\is_dir($dir = $bundle['path'].'/Resources/translations')) {
$dirs[] = $dir;
} else {
$nonExistingDirs[] = $dir;
}
if (\is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
$dirs[] = $dir;
} else {
$nonExistingDirs[] = $dir;
}
}

foreach ($config['paths'] as $dir) {
Expand All @@ -1153,16 +1146,6 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$nonExistingDirs[] = $defaultDir;
}

if (\is_dir($dir = $rootDir.'/Resources/translations')) {
if ($dir !== $defaultDir) {
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
}

$dirs[] = $dir;
} else {
$nonExistingDirs[] = $dir;
}

// Register translation resources
if ($dirs) {
$files = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ public function testDebugDefaultDirectory()
$this->assertRegExp('/unused/', $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 Loading Twig templates from 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(['foo' => 'foo'], ['bar' => 'bar']);
$tester->execute(['locale' => 'en']);

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

public function testDebugDefaultRootDirectory()
{
$this->fs->remove($this->translationDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,6 @@ 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 Symfony 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(['messages' => ['foo' => 'foo']]);
$tester->execute(['command' => 'translation:update', 'locale' => 'en', '--force' => true]);
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
}

public function testWriteMessagesForSpecificDomain()
{
$tester = $this->createCommandTester(['messages' => ['foo' => 'foo'], 'mydomain' => ['bar' => 'bar']]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
use Symfony\Component\Validator\Util\LegacyTranslatorProxy;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Workflow;

abstract class FrameworkExtensionTest extends TestCase
Expand Down Expand Up @@ -842,20 +841,6 @@ function ($directory) {
}
}

/**
* @group legacy
* @expectedDeprecation Translations directory "%s/Resources/translations" is deprecated since Symfony 4.2, use "%s/translations" instead.
*/
public function testLegacyTranslationsDirectory()
{
$container = $this->createContainerFromFile('full', ['kernel.root_dir' => __DIR__.'/Fixtures']);
$options = $container->getDefinition('translator.default')->getArgument(4);
$files = array_map('realpath', $options['resource_files']['en']);

$dir = str_replace('/', \DIRECTORY_SEPARATOR, __DIR__.'/Fixtures/Resources/translations/test_default.en.xlf');
$this->assertContains($dir, $files, '->registerTranslatorConfiguration() finds translation resources in legacy directory');
}

public function testTranslatorMultipleFallbacks()
{
$container = $this->createContainerFromFile('translator_fallbacks');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\AnnotationReaderPass;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\TranslationDebugPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -30,6 +29,5 @@ public function build(ContainerBuilder $container)
$extension->setCustomConfig(new CustomConfig());

$container->addCompilerPass(new AnnotationReaderPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new TranslationDebugPass());
}
}
0