|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2015-2017 Libre Informatique |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licenced under the GNU LGPL v3. |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Blast\Bundle\CoreBundle\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Blast\Bundle\CoreBundle\Generator\ArrayToYamlGenerator; |
|
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
19
|
|
|
use Symfony\Component\Finder\Finder; |
|
20
|
|
|
use Symfony\Component\DomCrawler\Crawler; |
|
21
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class GenerateAdminCommand. |
|
25
|
|
|
*/ |
|
26
|
|
|
class GenerateTranslationsCommand extends ContainerAwareCommand |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function configure() |
|
32
|
|
|
{ |
|
33
|
|
|
$this |
|
34
|
|
|
->setName('blast:generate:translations') |
|
35
|
|
|
->setDescription('Generates translation files from XLIFF to YAML') |
|
36
|
|
|
->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to generate translations for (ex: AcmeDemoBundle)') |
|
37
|
|
|
; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function isEnabled() |
|
44
|
|
|
{ |
|
45
|
|
|
return class_exists('Sensio\\Bundle\\GeneratorBundle\\SensioGeneratorBundle'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
|
|
$bundle = $input->getArgument('bundle'); |
|
54
|
|
|
$fs = new Filesystem(); |
|
55
|
|
|
$finder = new Finder(); |
|
56
|
|
|
$crawler = new Crawler(); |
|
57
|
|
|
|
|
58
|
|
|
$path = $this->getContainer()->get('kernel')->locateResource('@' . $bundle); |
|
59
|
|
|
$transPath = $path . 'Resources/translations/'; |
|
60
|
|
|
|
|
61
|
|
|
if (!$fs->exists($transPath)) { |
|
62
|
|
|
try { |
|
63
|
|
|
$fs->mkdir($transPath); |
|
64
|
|
|
} catch (IOExceptionInterface $e) { |
|
|
|
|
|
|
65
|
|
|
echo sprintf('An error occurred while creating your directory at %s', $e->getPath()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
foreach ($finder->files()->in($transPath) as $file) { |
|
70
|
|
|
$translations = []; |
|
71
|
|
|
|
|
72
|
|
|
$crawler->addXmlContent(file_get_contents($file->getPathName())); |
|
73
|
|
|
$crawler = $crawler->filter('trans-unit'); |
|
74
|
|
|
|
|
75
|
|
|
foreach ($crawler as $transUnit) { |
|
76
|
|
|
$source = $transUnit |
|
77
|
|
|
->getElementsByTagName('source') |
|
78
|
|
|
->item(0) |
|
79
|
|
|
->nodeValue |
|
80
|
|
|
; |
|
81
|
|
|
$source = str_replace("'", "''", $source); |
|
82
|
|
|
|
|
83
|
|
|
$target = $transUnit |
|
84
|
|
|
->getElementsByTagName('target') |
|
85
|
|
|
->item(0) |
|
86
|
|
|
->nodeValue |
|
87
|
|
|
; |
|
88
|
|
|
$target = str_replace("'", "''", $target); |
|
89
|
|
|
|
|
90
|
|
|
$translations[$source] = $target; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$ymlGenerator = new ArrayToYamlGenerator($file, __DIR__ . '/../Resources/skeleton'); |
|
94
|
|
|
$ymlGenerator->generate($translations, 'Messages.yml.twig'); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return 0; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.