Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
I18nPackCommand.php
Go to the documentation of this file.
1 <?php
7 
9 use Symfony\Component\Console\Command\Command;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 
18 class I18nPackCommand extends Command
19 {
23  const INPUT_KEY_SOURCE = 'source';
24  const INPUT_KEY_LOCALE = 'locale';
25  const INPUT_KEY_MODE = 'mode';
26  const INPUT_KEY_ALLOW_DUPLICATES = 'allow-duplicates';
32  const MODE_REPLACE = 'replace';
33 
37  const MODE_MERGE = 'merge';
38 
42  protected function configure()
43  {
44  $this->setName('i18n:pack')
45  ->setDescription('Saves language package');
46  $this->setDefinition([
47  new InputArgument(
48  self::INPUT_KEY_SOURCE,
49  InputArgument::REQUIRED,
50  'Path to source dictionary file with translations'
51  ),
52  new InputArgument(
53  self::INPUT_KEY_LOCALE,
54  InputArgument::REQUIRED,
55  'Target locale for dictionary, for example "de_DE"'
56  ),
57  new InputOption(
58  self::INPUT_KEY_MODE,
59  'm',
60  InputOption::VALUE_REQUIRED,
61  'Save mode for dictionary' . PHP_EOL . '- "replace" - replace language pack by new one' . PHP_EOL .
62  '- "merge" - merge language packages, by default "replace"',
63  self::MODE_REPLACE
64  ),
65  new InputOption(
66  self::INPUT_KEY_ALLOW_DUPLICATES,
67  'd',
68  InputOption::VALUE_NONE,
69  'Use the --allow-duplicates parameter to allow saving duplicates of translate.' .
70  ' Otherwise omit the parameter.'
71  ),
72  ]);
73  }
74 
79  protected function execute(InputInterface $input, OutputInterface $output)
80  {
81  $generator = ServiceLocator::getPackGenerator();
82  $mode = $input->getOption(self::INPUT_KEY_MODE);
83  if ($mode !== self::MODE_MERGE && $mode !== self::MODE_REPLACE) {
84  throw new \InvalidArgumentException("Possible values for 'mode' option are 'replace' and 'merge'");
85  }
86  $locale = $input->getArgument(self::INPUT_KEY_LOCALE);
87  $generator->generate(
88  $input->getArgument(self::INPUT_KEY_SOURCE),
89  $locale,
90  $input->getOption(self::INPUT_KEY_MODE),
91  $input->getOption(self::INPUT_KEY_ALLOW_DUPLICATES)
92  );
93  $output->writeln("<info>Successfully saved $locale language package.</info>");
94  return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
95  }
96 }
execute(InputInterface $input, OutputInterface $output)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15