Skip to content

Commit e47cc7e

Browse files
authored
Added download and sync commands (#54)
1 parent 4d195a2 commit e47cc7e

File tree

4 files changed

+97
-26
lines changed

4 files changed

+97
-26
lines changed

Command/DeleteObsoleteCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Question\ConfirmationQuestion;
20-
use Symfony\Component\DependencyInjection\ContainerInterface;
2120

21+
/**
22+
* @author Tobias Nyholm <[email protected]>
23+
*/
2224
class DeleteObsoleteCommand extends ContainerAwareCommand
2325
{
24-
/**
25-
* @var ContainerInterface
26-
*/
27-
private $container;
28-
2926
protected function configure()
3027
{
3128
$this

Command/DownloadCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP Translation package.
5+
*
6+
* (c) PHP Translation team <[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 Translation\Bundle\Command;
13+
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
use Translation\Bundle\Model\Configuration;
19+
use Translation\Bundle\Service\StorageService;
20+
21+
/**
22+
* @author Tobias Nyholm <[email protected]>
23+
*/
24+
class DownloadCommand extends ContainerAwareCommand
25+
{
26+
protected function configure()
27+
{
28+
$this
29+
->setName('translation:download')
30+
->setDescription('Replace local messages with messages from remote')
31+
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default');
32+
}
33+
34+
protected function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
$container = $this->getContainer();
37+
$configName = $input->getArgument('configuration');
38+
/** @var StorageService $storage */
39+
$storage = $container->get('php_translation.storage.'.$configName);
40+
$storage->download();
41+
}
42+
}

Command/ExtractCommand.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515
use Symfony\Component\Console\Input\InputArgument;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18-
use Symfony\Component\DependencyInjection\ContainerInterface;
1918
use Symfony\Component\Finder\Finder;
2019
use Translation\Bundle\Model\Configuration;
2120

21+
/**
22+
* @author Tobias Nyholm <[email protected]>
23+
*/
2224
class ExtractCommand extends ContainerAwareCommand
2325
{
24-
/**
25-
* @var ContainerInterface
26-
*/
27-
private $container;
28-
2926
protected function configure()
3027
{
3128
$this
@@ -38,34 +35,27 @@ protected function configure()
3835
protected function execute(InputInterface $input, OutputInterface $output)
3936
{
4037
$container = $this->getContainer();
41-
$configName = $input->getArgument('configuration');
42-
$config = $container->get('php_translation.configuration_manager')->getConfiguration($configName);
4338
$importer = $container->get('php_translation.importer');
39+
$config = $container->get('php_translation.configuration_manager')
40+
->getConfiguration($input->getArgument('configuration'));
4441

4542
$locales = [];
4643
if ($inputLocale = $input->getArgument('locale')) {
4744
$locales = [$inputLocale];
4845
}
4946

50-
$catalogues = $container->get('php_translation.catalogue_fetcher')->getCatalogues($config, $locales);
47+
$catalogues = $container->get('php_translation.catalogue_fetcher')
48+
->getCatalogues($config, $locales);
49+
5150
$finder = $this->getConfiguredFinder($config);
5251
$results = $importer->extractToCatalogues($finder, $catalogues, [
5352
'blacklist_domains' => $config->getBlacklistDomains(),
5453
'whitelist_domains' => $config->getWhitelistDomains(),
5554
'project_root' => $config->getProjectRoot(),
5655
]);
5756

58-
$writer = $container->get('translation.writer');
59-
foreach ($results as $result) {
60-
$writer->writeTranslations(
61-
$result,
62-
$config->getOutputFormat(),
63-
[
64-
'path' => $config->getOutputDir(),
65-
'default_locale' => $container->getParameter('php_translation.default_locale'),
66-
]
67-
);
68-
}
57+
$container->get('php_translation.catalogue_writer')
58+
->writeCatalogues($config, $results);
6959
}
7060

7161
/**

Command/SyncCommand.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP Translation package.
5+
*
6+
* (c) PHP Translation team <[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 Translation\Bundle\Command;
13+
14+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
use Translation\Bundle\Model\Configuration;
19+
use Translation\Bundle\Service\StorageService;
20+
21+
/**
22+
* @author Tobias Nyholm <[email protected]>
23+
*/
24+
class SyncCommand extends ContainerAwareCommand
25+
{
26+
protected function configure()
27+
{
28+
$this
29+
->setName('translation:sync')
30+
->setDescription('Sync the translations with the remote storage')
31+
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default');
32+
}
33+
34+
protected function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
$container = $this->getContainer();
37+
$configName = $input->getArgument('configuration');
38+
/** @var StorageService $storage */
39+
$storage = $container->get('php_translation.storage.'.$configName);
40+
$storage->sync();
41+
}
42+
}

0 commit comments

Comments
 (0)