1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\TranslationsBundle\Command; |
13
|
|
|
|
14
|
|
|
use ONGR\TranslationsBundle\Service\Export\ExportManager; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Input\InputOption; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Exports translations. |
23
|
|
|
*/ |
24
|
|
|
class ExportCommand extends ContainerAwareCommand |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
4 |
|
*/ |
29
|
|
View Code Duplication |
protected function configure() |
|
|
|
|
30
|
4 |
|
{ |
31
|
4 |
|
$this->setName('ongr:translations:export'); |
32
|
4 |
|
$this->setDescription('Export all translations from ES to yaml.'); |
33
|
4 |
|
$this->addOption( |
34
|
4 |
|
'locales', |
35
|
4 |
|
'l', |
36
|
4 |
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
37
|
|
|
'Export only these locales, instead of using the managed locales.' |
38
|
4 |
|
); |
39
|
4 |
|
$this->addOption( |
40
|
4 |
|
'force', |
41
|
4 |
|
'f', |
42
|
4 |
|
InputOption::VALUE_NONE, |
43
|
4 |
|
'If set, the bundle will export all translations, regardless of status' |
44
|
|
|
); |
45
|
4 |
|
$this->addArgument( |
46
|
|
|
'bundle', |
47
|
|
|
InputArgument::OPTIONAL, |
48
|
|
|
'Import translations for the specific bundle.' |
49
|
|
|
); |
50
|
4 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
4 |
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
4 |
|
{ |
57
|
1 |
|
/** @var ExportManager $export */ |
58
|
|
|
$export = $this->getContainer()->get('ongr_translations.export'); |
59
|
|
|
$bundle = $input->getArgument('bundle'); |
60
|
4 |
|
|
61
|
4 |
|
$locales = $input->getOption('locales', $this->getContainer()->getParameter('ongr_translations.locales')); |
|
|
|
|
62
|
|
|
$export->setLocales($locales); |
63
|
|
|
|
64
|
|
|
if ($bundle) { |
|
|
|
|
65
|
|
|
// $output->writeln("<info>*** Importing {$bundleName} translation files ***</info>"); |
|
|
|
|
66
|
|
|
// $bundle = $this->getContainer()->get('kernel')->getBundle($bundleNames); |
67
|
|
|
// |
68
|
|
|
// foreach ($bundleNames as $bundleName) { |
69
|
|
|
// $dir = $this->getContainer()->get('kernel')->getBundle($bundleName); |
70
|
|
|
// $import->importTranslationFiles($bundle); |
71
|
|
|
// } |
72
|
|
|
} else { |
73
|
|
|
$export->export(['messages'], $input->getOption('force')); |
74
|
|
|
$export->export($this->getContainer()->getParameter('ongr_translations.bundles'), $input->getOption('force')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$prettify = function ($array) { |
78
|
|
|
return !empty($array) ? implode('</comment><info>`, `</info><comment>', $array) : 'all'; |
79
|
|
|
}; |
80
|
|
|
|
81
|
|
|
$output->writeln( |
82
|
|
|
sprintf( |
83
|
|
|
'<info>Successfully exported translations in `</info>' |
84
|
|
|
. '<comment>%s</comment><info>` locale(s) for `</info>', |
85
|
|
|
$prettify($locales) |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.