Skip to content

Commit b02ae50

Browse files
natewiebe13fabpot
authored andcommitted
[FrameworkBundle][Translation] Extract translation IDs from all of src
1 parent f0e076a commit b02ae50

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class TranslationDebugCommand extends Command
5555
private $defaultTransPath;
5656
private $defaultViewsPath;
5757
private $transPaths;
58-
private $viewsPaths;
58+
private $codePaths;
5959

60-
public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $viewsPaths = [])
60+
public function __construct(TranslatorInterface $translator, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = [])
6161
{
6262
parent::__construct();
6363

@@ -67,7 +67,7 @@ public function __construct(TranslatorInterface $translator, TranslationReaderIn
6767
$this->defaultTransPath = $defaultTransPath;
6868
$this->defaultViewsPath = $defaultViewsPath;
6969
$this->transPaths = $transPaths;
70-
$this->viewsPaths = $viewsPaths;
70+
$this->codePaths = $codePaths;
7171
}
7272

7373
/**
@@ -139,9 +139,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
139139
if ($this->defaultTransPath) {
140140
$transPaths[] = $this->defaultTransPath;
141141
}
142-
$viewsPaths = $this->viewsPaths;
142+
$codePaths = $this->codePaths;
143+
$codePaths[] = $kernel->getProjectDir().'/src';
143144
if ($this->defaultViewsPath) {
144-
$viewsPaths[] = $this->defaultViewsPath;
145+
$codePaths[] = $this->defaultViewsPath;
145146
}
146147

147148
// Override with provided Bundle info
@@ -150,19 +151,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
150151
$bundle = $kernel->getBundle($input->getArgument('bundle'));
151152
$bundleDir = $bundle->getPath();
152153
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
153-
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
154+
$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
154155
if ($this->defaultTransPath) {
155156
$transPaths[] = $this->defaultTransPath;
156157
}
157158
if ($this->defaultViewsPath) {
158-
$viewsPaths[] = $this->defaultViewsPath;
159+
$codePaths[] = $this->defaultViewsPath;
159160
}
160161
} catch (\InvalidArgumentException $e) {
161162
// such a bundle does not exist, so treat the argument as path
162163
$path = $input->getArgument('bundle');
163164

164165
$transPaths = [$path.'/translations'];
165-
$viewsPaths = [$path.'/templates'];
166+
$codePaths = [$path.'/templates'];
166167

167168
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
168169
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
@@ -172,12 +173,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
172173
foreach ($kernel->getBundles() as $bundle) {
173174
$bundleDir = $bundle->getPath();
174175
$transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
175-
$viewsPaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
176+
$codePaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
176177
}
177178
}
178179

179180
// Extract used messages
180-
$extractedCatalogue = $this->extractMessages($locale, $viewsPaths);
181+
$extractedCatalogue = $this->extractMessages($locale, $codePaths);
181182

182183
// Load defined messages
183184
$currentCatalogue = $this->loadCurrentMessages($locale, $transPaths);

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class TranslationUpdateCommand extends Command
5151
private $defaultTransPath;
5252
private $defaultViewsPath;
5353
private $transPaths;
54-
private $viewsPaths;
54+
private $codePaths;
5555

56-
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $viewsPaths = [])
56+
public function __construct(TranslationWriterInterface $writer, TranslationReaderInterface $reader, ExtractorInterface $extractor, string $defaultLocale, string $defaultTransPath = null, string $defaultViewsPath = null, array $transPaths = [], array $codePaths = [])
5757
{
5858
parent::__construct();
5959

@@ -64,7 +64,7 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade
6464
$this->defaultTransPath = $defaultTransPath;
6565
$this->defaultViewsPath = $defaultViewsPath;
6666
$this->transPaths = $transPaths;
67-
$this->viewsPaths = $viewsPaths;
67+
$this->codePaths = $codePaths;
6868
}
6969

7070
/**
@@ -150,9 +150,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
150150
if ($this->defaultTransPath) {
151151
$transPaths[] = $this->defaultTransPath;
152152
}
153-
$viewsPaths = $this->viewsPaths;
153+
$codePaths = $this->codePaths;
154+
$codePaths[] = $kernel->getProjectDir().'/src';
154155
if ($this->defaultViewsPath) {
155-
$viewsPaths[] = $this->defaultViewsPath;
156+
$codePaths[] = $this->defaultViewsPath;
156157
}
157158
$currentName = 'default directory';
158159

@@ -162,20 +163,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
162163
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
163164
$bundleDir = $foundBundle->getPath();
164165
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
165-
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
166+
$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
166167
if ($this->defaultTransPath) {
167168
$transPaths[] = $this->defaultTransPath;
168169
}
169170
if ($this->defaultViewsPath) {
170-
$viewsPaths[] = $this->defaultViewsPath;
171+
$codePaths[] = $this->defaultViewsPath;
171172
}
172173
$currentName = $foundBundle->getName();
173174
} catch (\InvalidArgumentException $e) {
174175
// such a bundle does not exist, so treat the argument as path
175176
$path = $input->getArgument('bundle');
176177

177178
$transPaths = [$path.'/translations'];
178-
$viewsPaths = [$path.'/templates'];
179+
$codePaths = [$path.'/templates'];
179180

180181
if (!is_dir($transPaths[0]) && !isset($transPaths[1])) {
181182
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
@@ -190,7 +191,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
190191
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
191192
$io->comment('Parsing templates...');
192193
$this->extractor->setPrefix($input->getOption('prefix'));
193-
foreach ($viewsPaths as $path) {
194+
foreach ($codePaths as $path) {
194195
if (is_dir($path) || is_file($path)) {
195196
$this->extractor->extract($path, $extractedCatalogue);
196197
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected function tearDown(): void
139139
$this->fs->remove($this->translationDir);
140140
}
141141

142-
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
142+
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $codePaths = []): CommandTester
143143
{
144144
$translator = $this->createMock(Translator::class);
145145
$translator
@@ -190,7 +190,7 @@ function ($path, $catalogue) use ($loadedMessages) {
190190
->method('getContainer')
191191
->willReturn($container);
192192

193-
$command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths);
193+
$command = new TranslationDebugCommand($translator, $loader, $extractor, $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths);
194194

195195
$application = new Application($kernel);
196196
$application->add($command);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function tearDown(): void
148148
/**
149149
* @return CommandTester
150150
*/
151-
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
151+
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $codePaths = [])
152152
{
153153
$translator = $this->createMock(Translator::class);
154154
$translator
@@ -209,7 +209,7 @@ function ($path, $catalogue) use ($loadedMessages) {
209209
->method('getContainer')
210210
->willReturn($container);
211211

212-
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $viewsPaths);
212+
$command = new TranslationUpdateCommand($writer, $loader, $extractor, 'en', $this->translationDir.'/translations', $this->translationDir.'/templates', $transPaths, $codePaths);
213213

214214
$application = new Application($kernel);
215215
$application->add($command);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy