From d0dda80197b3f1b91bf8e290a1eca7342a82db19 Mon Sep 17 00:00:00 2001 From: Pierre Rolland Date: Fri, 30 Oct 2015 16:37:10 +0100 Subject: [PATCH 1/2] #37 Added possibility to pull specific files --- README.md | 8 ++++++++ src/Openl10n/Cli/Command/PullCommand.php | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index c8d11d1..b3cf6a2 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,14 @@ You can select the files you want to push to the server by adding a file name li openl10n push --locale=all app/Resources/fr.yml config/translations/de.yml ``` +### Select files to download + +Same thing here: + +```shell +openl10n pull --locale=all app/Resources/fr.yml config/translations/de.yml +``` + ## License OpenLocalization is released under the MIT License. diff --git a/src/Openl10n/Cli/Command/PullCommand.php b/src/Openl10n/Cli/Command/PullCommand.php index 7a06765..e59bf7f 100644 --- a/src/Openl10n/Cli/Command/PullCommand.php +++ b/src/Openl10n/Cli/Command/PullCommand.php @@ -2,6 +2,7 @@ namespace Openl10n\Cli\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -23,6 +24,11 @@ protected function configure() 'The locale id, "default" for the source, "all" for every locales found', ['default'] ) + ->addArgument( + 'files', + InputArgument::IS_ARRAY, + 'File list you want to pull from the server' + ) ; } @@ -79,6 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Iterate over resources // $fileSets = $this->get('file_handler')->getFileSets(); + $fileFilter = $input->getArgument('files'); foreach ($fileSets as $fileSet) { $files = $fileSet->getFiles(); @@ -90,6 +97,11 @@ protected function execute(InputInterface $input, OutputInterface $output) $resourceIdentifier = $file->getPathname(['locale' => $defaultLocale]); $locale = $file->getAttribute('locale'); + // Skip unwanted files + if (!empty($fileFilter) && !in_array($file->getRelativePathname(), $fileFilter)) { + continue; + } + if (!isset($resources[$resourceIdentifier])) { $output->writeln(sprintf('Skipping file %s', $file->getRelativePathname())); continue; From 9d2bd77f8099f4b6a725817c7e1edc57bd2c9212 Mon Sep 17 00:00:00 2001 From: Pierre Rolland Date: Mon, 14 Mar 2016 19:09:03 +0100 Subject: [PATCH 2/2] Added a "remove translation" command --- src/Openl10n/Cli/ApplicationFactory.php | 1 + .../Cli/Command/RemoveTranslationCommand.php | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/Openl10n/Cli/Command/RemoveTranslationCommand.php diff --git a/src/Openl10n/Cli/ApplicationFactory.php b/src/Openl10n/Cli/ApplicationFactory.php index ab772e0..f4f511d 100644 --- a/src/Openl10n/Cli/ApplicationFactory.php +++ b/src/Openl10n/Cli/ApplicationFactory.php @@ -46,6 +46,7 @@ protected function getDefaultCommands() new Command\InitCommand(), new Command\PullCommand(), new Command\PushCommand(), + new Command\RemoveTranslationCommand() ]; } diff --git a/src/Openl10n/Cli/Command/RemoveTranslationCommand.php b/src/Openl10n/Cli/Command/RemoveTranslationCommand.php new file mode 100644 index 0000000..41c9694 --- /dev/null +++ b/src/Openl10n/Cli/Command/RemoveTranslationCommand.php @@ -0,0 +1,53 @@ +setName('remove-translation') + ->setDescription('Removes a translation given its identifier') + ->addArgument( + 'identifier', + InputArgument::REQUIRED, + 'Translation\'s identifier you want to remove' + ) + ; + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $api = $this->get('api'); + /* @var ProjectEntryPoint $projectApi */ + $projectApi = $api->getEntryPoint('project'); + /* @var TranslationEntryPoint $translationApi */ + $translationApi = $api->getEntryPoint('translation'); + + $projectSlug = $this->get('project_handler')->getProjectSlug(); + $project = $projectApi->get($projectSlug); + + $identifier = $input->getArgument('identifier'); + + $translation = $translationApi->findOneByIdentifier($project, $identifier); + if (!$translation) { + $output->writeln(sprintf('Translation "%s" does not exist', $identifier)); + } else { + $output->writeln(sprintf('Removing translation "%s"', $identifier)); + $translationApi->delete($translation); + } + } +}