[FrameworkBundle] Deprecate support for legacy translations and views directories
This commit is contained in:
parent
c11fe350a8
commit
a7a8aad46f
@ -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
|
||||
---------
|
||||
|
@ -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
|
||||
--------------
|
||||
|
@ -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
|
||||
-----
|
||||
|
@ -131,11 +131,25 @@ EOF
|
||||
$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;
|
||||
}
|
||||
@ -146,35 +160,60 @@ EOF
|
||||
$bundle = $kernel->getBundle($input->getArgument('bundle'));
|
||||
$transPaths = array($bundle->getPath().'/Resources/translations');
|
||||
if ($this->defaultTransPath) {
|
||||
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
|
||||
$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) : 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');
|
||||
|
||||
if (!is_dir($transPaths[0])) {
|
||||
$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]) && !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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,11 +121,25 @@ EOF
|
||||
$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;
|
||||
}
|
||||
@ -137,22 +151,44 @@ EOF
|
||||
$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');
|
||||
|
||||
if (!is_dir($transPaths[0])) {
|
||||
$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]) && !isset($transPaths[1])) {
|
||||
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
|
||||
}
|
||||
}
|
||||
|
@ -65,6 +65,23 @@ class TranslationDebugCommandTest extends TestCase
|
||||
$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 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);
|
||||
@ -82,14 +99,16 @@ class TranslationDebugCommandTest extends TestCase
|
||||
|
||||
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());
|
||||
@ -114,8 +133,6 @@ class TranslationDebugCommandTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
|
||||
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;
|
||||
|
||||
@ -80,6 +81,23 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
$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(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')));
|
||||
@ -91,8 +109,6 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
{
|
||||
$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');
|
||||
}
|
||||
@ -174,10 +190,12 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
->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');
|
||||
|
||||
|
Reference in New Issue
Block a user