Skip to content

[FrameworkBundle][Translation] Extract translation IDs from all of src #40229

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
Mar 5, 2021
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 @@ -55,9 +55,9 @@ class TranslationDebugCommand extends Command
private $defaultTransPath;
private $defaultViewsPath;
private $transPaths;
private $viewsPaths;
private $codePaths;

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

Expand All @@ -67,7 +67,7 @@ public function __construct(TranslatorInterface $translator, TranslationReaderIn
$this->defaultTransPath = $defaultTransPath;
$this->defaultViewsPath = $defaultViewsPath;
$this->transPaths = $transPaths;
$this->viewsPaths = $viewsPaths;
$this->codePaths = $codePaths;
}

/**
Expand Down Expand Up @@ -139,9 +139,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = $this->viewsPaths;
$codePaths = $this->codePaths;
$codePaths[] = $kernel->getProjectDir().'/src';
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
$codePaths[] = $this->defaultViewsPath;
}

// Override with provided Bundle info
Expand All @@ -150,19 +151,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$bundle = $kernel->getBundle($input->getArgument('bundle'));
$bundleDir = $bundle->getPath();
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
$codePaths[] = $this->defaultViewsPath;
}
} catch (\InvalidArgumentException $e) {
// such a bundle does not exist, so treat the argument as path
$path = $input->getArgument('bundle');

$transPaths = [$path.'/translations'];
$viewsPaths = [$path.'/templates'];
$codePaths = [$path.'/templates'];

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 @@ -172,12 +173,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($kernel->getBundles() as $bundle) {
$bundleDir = $bundle->getPath();
$transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
$viewsPaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
$codePaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
}
}

// Extract used messages
$extractedCatalogue = $this->extractMessages($locale, $viewsPaths);
$extractedCatalogue = $this->extractMessages($locale, $codePaths);

// Load defined messages
$currentCatalogue = $this->loadCurrentMessages($locale, $transPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class TranslationUpdateCommand extends Command
private $defaultTransPath;
private $defaultViewsPath;
private $transPaths;
private $viewsPaths;
private $codePaths;

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

Expand All @@ -64,7 +64,7 @@ public function __construct(TranslationWriterInterface $writer, TranslationReade
$this->defaultTransPath = $defaultTransPath;
$this->defaultViewsPath = $defaultViewsPath;
$this->transPaths = $transPaths;
$this->viewsPaths = $viewsPaths;
$this->codePaths = $codePaths;
}

/**
Expand Down Expand Up @@ -150,9 +150,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
$viewsPaths = $this->viewsPaths;
$codePaths = $this->codePaths;
$codePaths[] = $kernel->getProjectDir().'/src';
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
$codePaths[] = $this->defaultViewsPath;
}
$currentName = 'default directory';

Expand All @@ -162,20 +163,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
$bundleDir = $foundBundle->getPath();
$transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
$viewsPaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
$codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
if ($this->defaultTransPath) {
$transPaths[] = $this->defaultTransPath;
}
if ($this->defaultViewsPath) {
$viewsPaths[] = $this->defaultViewsPath;
$codePaths[] = $this->defaultViewsPath;
}
$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'];
$viewsPaths = [$path.'/templates'];
$codePaths = [$path.'/templates'];

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 @@ -190,7 +191,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
$io->comment('Parsing templates...');
$this->extractor->setPrefix($input->getOption('prefix'));
foreach ($viewsPaths as $path) {
foreach ($codePaths as $path) {
if (is_dir($path) || is_file($path)) {
$this->extractor->extract($path, $extractedCatalogue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function tearDown(): void
$this->fs->remove($this->translationDir);
}

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

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

$application = new Application($kernel);
$application->add($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function tearDown(): void
/**
* @return CommandTester
*/
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
private function createCommandTester($extractedMessages = [], $loadedMessages = [], KernelInterface $kernel = null, array $transPaths = [], array $codePaths = [])
{
$translator = $this->createMock(Translator::class);
$translator
Expand Down Expand Up @@ -209,7 +209,7 @@ function ($path, $catalogue) use ($loadedMessages) {
->method('getContainer')
->willReturn($container);

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

$application = new Application($kernel);
$application->add($command);
Expand Down