[FrameworkBundle][Translation] Extract translation IDs from all of src
This commit is contained in:
parent
f0e076a013
commit
b02ae5050c
@ -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();
|
||||
|
||||
@ -67,7 +67,7 @@ class TranslationDebugCommand extends Command
|
||||
$this->defaultTransPath = $defaultTransPath;
|
||||
$this->defaultViewsPath = $defaultViewsPath;
|
||||
$this->transPaths = $transPaths;
|
||||
$this->viewsPaths = $viewsPaths;
|
||||
$this->codePaths = $codePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,9 +139,10 @@ EOF
|
||||
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
|
||||
@ -150,19 +151,19 @@ EOF
|
||||
$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]));
|
||||
@ -172,12 +173,12 @@ EOF
|
||||
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);
|
||||
|
@ -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();
|
||||
|
||||
@ -64,7 +64,7 @@ class TranslationUpdateCommand extends Command
|
||||
$this->defaultTransPath = $defaultTransPath;
|
||||
$this->defaultViewsPath = $defaultViewsPath;
|
||||
$this->transPaths = $transPaths;
|
||||
$this->viewsPaths = $viewsPaths;
|
||||
$this->codePaths = $codePaths;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,9 +150,10 @@ EOF
|
||||
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';
|
||||
|
||||
@ -162,12 +163,12 @@ EOF
|
||||
$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) {
|
||||
@ -175,7 +176,7 @@ EOF
|
||||
$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]));
|
||||
@ -190,7 +191,7 @@ EOF
|
||||
$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);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class TranslationDebugCommandTest extends TestCase
|
||||
$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
|
||||
@ -190,7 +190,7 @@ class TranslationDebugCommandTest extends TestCase
|
||||
->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);
|
||||
|
@ -148,7 +148,7 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
/**
|
||||
* @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
|
||||
@ -209,7 +209,7 @@ class TranslationUpdateCommandTest extends TestCase
|
||||
->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);
|
||||
|
Reference in New Issue
Block a user