8000 [FrameworkBundle] Deprecate support for legacy translations and views… · symfony/symfony@a7a8aad · GitHub
[go: up one dir, main page]

Skip to content

Commit a7a8aad

Browse files
author
Robin Chalas
committed
[FrameworkBundle] Deprecate support for legacy translations and views directories
1 parent c11fe35 commit a7a8aad

File tree

7 files changed

+146
-33
lines changed

7 files changed

+146
-33
lines changed

UPGRADE-4.2.md

Lines changed: 1 addition & 0 deletions
< 6D40 /tr>
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ FrameworkBundle
156156
set the "APP_DEBUG" environment variable to "0" instead.
157157
* The `Templating\Helper\TranslatorHelper::transChoice()` method has been deprecated, use the `trans()` one instead with a `%count%` parameter.
158158
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
159+
* Support for the legacy directory structure in `translation:update` and `debug:translation` commands has been deprecated.
159160

160161
Messenger
161162
---------

UPGRADE-5.0.md

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

174175
HttpFoundation
175176
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CHANGELOG
2525
* Deprecated `CachePoolPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPass` instead.
2626
* Deprecated `CachePoolPrunerPass`. Use `Symfony\Component\Cache\DependencyInjection\CachePoolPrunerPass` instead.
2727
* Deprecated support for legacy translations directories `src/Resources/translations/` and `src/Resources/<BundleName>/translations/`, use `translations/` instead.
28+
* Deprecated support for the legacy directory structure in `translation:update` and `debug:translation` commands.
2829

2930
4.1.0
3031
-----

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
131131
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');
132132

133133
// Define Root Paths
134-
$transPaths = array($rootDir.'/Resources/translations');
134+
$transPaths = array();
135+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
136+
if ($dir !== $this->defaultTransPath) {
137+
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
138+
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
139+
}
140+
$transPaths[] = $dir;
141+
}
135142
if ($this->defaultTransPath) {
136143
$transPaths[] = $this->defaultTransPath;
137144
}
138-
$viewsPaths = array($rootDir.'/Resources/views');
145+
$viewsPaths = array();
146+
if (is_dir($dir = $rootDir.'/Resources/views')) {
147+
if ($dir !== $this->defaultViewsPath) {
148+
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
149+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
150+
}
151+
$viewsPaths[] = $dir;
152+
}
139153
if ($this->defaultViewsPath) {
140154
$viewsPaths[] = $this->defaultViewsPath;
141155
}
@@ -146,35 +160,60 @@ protected function execute(InputInterface $input, OutputInterface $output)
146160
$bundle = $kernel->getBundle($input->getArgument('bundle'));
147161
$transPaths = array($bundle->getPath().'/Resources/translations');
148162
if ($this->defaultTransPath) {
149-
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
163+
$transPaths[] = $this->defaultTransPath;
164+
}
165+
if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
166+
$transPaths[] = $dir;
167+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $dir, $bundle->getName());
168+
@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);
150169
}
151-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
152170
$viewsPaths = array($bundle->getPath().'/Resources/views');
153171
if ($this->defaultViewsPath) {
154-
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
172+
$viewsPaths[] = $this->defaultViewsPath;
173+
}
174+
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
175+
$viewsPaths[] = $dir;
176+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $dir);
177+
@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);
155178
}
156-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
157179
} catch (\InvalidArgumentException $e) {
158180
// such a bundle does not exist, so treat the argument as path
159-
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
160-
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
181+
$path = $input->getArgument('bundle');
182+
183+
$transPaths = array($path.'/translations');
184+
if (is_dir($dir = $path.'/Resources/translations')) {
185+
if ($dir !== $this->defaultTransPath) {
186+
@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);
187+
}
188+
$transPaths[] = $dir;
189+
}
161190

162-
if (!is_dir($transPaths[0])) {
191+
$viewsPaths = array($path.'/templates');
192+
if (is_dir($dir = $path.'/Resources/views')) {
193+
if ($dir !== $this->defaultViewsPath) {
194+
@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);
195+
}
196+
$viewsPaths[] = $dir;
197+
}
198+
199+
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
163200
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
164201
}
165202
}
166203
} elseif ($input->getOption('all')) {
167204
foreach ($kernel->getBundles() as $bundle) {
168205
$transPaths[] = $bundle->getPath().'/Resources/translations';
169-
if ($this->defaultTransPath) {
170-
$transPaths[] = $this->defaultTransPath.'/'.$bundle->getName();
206+
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName()))) {
207+
$transPaths[] = $deprecatedPath;
208+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
209+
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
171210
}
172-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $bundle->getName());
173-
$viewsPaths[] = $bundle->getPath().'/Resources/views';
174-
if ($this->defaultViewsPath) {
175-
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$bundle->getName();
211+
$viewsPaths[] = array($bundle->getPath().'/Resources/views');
212+
if (is_dir($deprecatedPath = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName()))) {
213+
$viewsPaths[] = $deprecatedPath;
214+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $bundle->getName(), $deprecatedPath);
215+
@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);
176216
}
177-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $bundle->getName());
178217
}
179218
}
180219

src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
121121
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');
122122

123123
// Define Root Paths
124-
$transPaths = array($rootDir.'/Resources/translations');
124+
$transPaths = array();
125+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
126+
if ($dir !== $this->defaultTransPath) {
127+
$notice = sprintf('Storing translations in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
128+
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
129+
}
130+
$transPaths[] = $dir;
131+
}
125132
if ($this->defaultTransPath) {
126133
$transPaths[] = $this->defaultTransPath;
127134
}
128-
$viewsPaths = array($rootDir.'/Resources/views');
135+
$viewsPaths = array();
136+
if (is_dir($dir = $rootDir.'/Resources/views')) {
137+
if ($dir !== $this->defaultViewsPath) {
138+
$notice = sprintf('Storing templates in the "%s" directory is deprecated since Symfony 4.2, ', $dir);
139+
@trigger_error($notice.($this->defaultViewsPath ? sprintf('use the "%s" directory instead.', $this->defaultViewsPath) : 'configure and use "twig.default_path" instead.'), E_USER_DEPRECATED);
140+
}
141+
$viewsPaths[] = $dir;
142+
}
129143
if ($this->defaultViewsPath) {
130144
$viewsPaths[] = $this->defaultViewsPath;
131145
}
@@ -137,22 +151,44 @@ protected function execute(InputInterface $input, OutputInterface $output)
137151
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
138152
$transPaths = array($foundBundle->getPath().'/Resources/translations');
139153
if ($this->defaultTransPath) {
140-
$transPaths[] = $this->defaultTransPath.'/'.$foundBundle->getName();
154+
$transPaths[] = $this->defaultTransPath;
155+
}
156+
if (is_dir($dir = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName()))) {
157+
$transPaths[] = $dir;
158+
$notice = sprintf('Storing translations files for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
159+
@trigger_error($notice.($this->defaultTransPath ? sprintf('use the "%s" directory instead.', $this->defaultTransPath) : 'configure and use "framework.translator.default_path" instead.'), E_USER_DEPRECATED);
141160
}
142-
$transPaths[] = sprintf('%s/Resources/%s/translations', $rootDir, $foundBundle->getName());
143161
$viewsPaths = array($foundBundle->getPath().'/Resources/views');
144162
if ($this->defaultViewsPath) {
145-
$viewsPaths[] = $this->defaultViewsPath.'/bundles/'.$foundBundle->getName();
163+
$viewsPaths[] = $this->defaultViewsPath;
164+
}
165+
if (is_dir($dir = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName()))) {
166+
$viewsPaths[] = $dir;
167+
$notice = sprintf('Storing templates for "%s" in the "%s" directory is deprecated since Symfony 4.2, ', $foundBundle->getName(), $dir);
168+
@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);
146169
}
147-
$viewsPaths[] = sprintf('%s/Resources/%s/views', $rootDir, $foundBundle->getName());
148170
$currentName = $foundBundle->getName();
149171
} catch (\InvalidArgumentException $e) {
150172
// such a bundle does not exist, so treat the argument as path
151-
$transPaths = array($input->getArgument('bundle').'/Resources/translations');
152-
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
153-
$currentName = $transPaths[0];
173+
$path = $input->getArgument('bundle');
174+
175+
$transPaths = array($path.'/translations');
176+
if (is_dir($dir = $path.'/Resources/translations')) {
177+
if ($dir !== $this->defaultTransPath) {
178+
@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);
179+
}
180+
$transPaths[] = $dir;
181+
}
182+
183+
$viewsPaths = array($path.'/templates');
184+
if (is_dir($dir = $path.'/Resources/views')) {
185+
if ($dir !== $this->defaultViewsPath) {
186+
@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);
187+
}
188+
$viewsPaths[] = $dir;
189+
}
154190

155-
if (!is_dir($transPaths[0])) {
191+
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
156192
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
157193
}
158194
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public function testDebugDefaultDirectory()
6565
$this->assertRegExp('/unused/', $tester->getDisplay());
6666
}
6767

68+
/**
69+
* @group legacy
70+
* @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.
71+
* @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.
72+
*/
73+
public function testDebugLegacyDefaultDirectory()
74+
{
75+
$this->fs->mkdir($this->translationDir.'/Resources/translations');
76+
$this->fs->mkdir($this->translationDir.'/Resources/views');
77+
78+
$tester = $this->createCommandTester(array('foo' => 'foo'), array('bar' => 'bar'));
79+
$tester->execute(array('locale' => 'en'));
80+
81+
$this->assertRegExp('/missing/', $tester->getDisplay());
82+
$this->assertRegExp('/unused/', $tester->getDisplay());
83+
}
84+
6885
public function testDebugDefaultRootDirectory()
6986
{
7087
$this->fs->remove($this->translationDir);
@@ -82,14 +99,16 @@ public function testDebugDefaultRootDirectory()
8299

83100
public function testDebugCustomDirectory()
84101
{
102+
$this->fs->mkdir($this->translationDir.'/customDir/translations');
103+
$this->fs->mkdir($this->translationDir.'/customDir/templates');
85104
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
86105
$kernel->expects($this->once())
87106
->method('getBundle')
88-
->with($this->equalTo($this->translationDir))
107+
->with($this->equalTo($this->translationDir.'/customDir'))
89108
->willThrowException(new \InvalidArgumentException());
90109

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

94113
$this->assertRegExp('/missing/', $tester->getDisplay());
95114
$this->assertRegExp('/unused/', $tester->getDisplay());
@@ -114,8 +133,6 @@ protected function setUp()
114133
{
115134
$this->fs = new Filesystem();
116135
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
117-
$this->fs->mkdir($this->translationDir.'/Resources/translations');
118-
$this->fs->mkdir($this->translationDir.'/Resources/views');
119136
$this->fs->mkdir($this->translationDir.'/translations');
120137
$this->fs->mkdir($this->translationDir.'/templates');
121138
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\Command\TranslationUpdateCommand;
1616
use Symfony\Bundle\FrameworkBundle\Console\Application;
1717
use Symfony\Component\Console\Tester\CommandTester;
18+
use Symfony\Component\DependencyInjection\Container;
1819
use Symfony\Component\Filesystem\Filesystem;
1920
use Symfony\Component\HttpKernel;
2021

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

84+
/**
85+
* @group legacy
86+
* @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.
87+
* @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.
88+
*/
89+
public function testWriteMessagesInLegacyRootDirectory()
90+
{
91+
$this->fs->remove($this->translationDir);
92+
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
93+
$this->fs->mkdir($this->translationDir.'/Resources/translations');
94+
$this->fs->mkdir($this->translationDir.'/Resources/views');
95+
96+
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo')));
97+
$tester->execute(array('command' => 'translation:update', 'locale' => 'en', '--force' => true));
98+
$this->assertRegExp('/Translation files were successfully updated./', $tester->getDisplay());
99+
}
100+
83101
public function testWriteMessagesForSpecificDomain()
84102
{
85103
$tester = $this->createCommandTester(array('messages' => array('foo' => 'foo'), 'mydomain' => array('bar' => 'bar')));
@@ -91,8 +109,6 @@ protected function setUp()
91109
{
92110
$this->fs = new Filesystem();
93111
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf_translation', true);
94-
$this->fs->mkdir($this->translationDir.'/Resources/translations');
95-
$this->fs->mkdir($this->translationDir.'/Resources/views');
96112
$this->fs->mkdir($this->translationDir.'/translations');
97113
$this->fs->mkdir($this->translationDir.'/templates');
98114
}
@@ -174,10 +190,12 @@ private function createCommandTester($extractedMessages = array(), $loadedMessag
174190
->method('getBundles')
175191
->will($this->returnValue(array()));
176192

193+
$container = new Container();
194+
$container->setParameter('kernel.root_dir', $this->translationDir);
177195
$kernel
178196
->expects($this->any())
179197
->method('getContainer')
180-
->will($this->returnValue($this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock()));
198+
->will($this->returnValue($container));
181199

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

0 commit comments

Comments
 (0)
0