PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.5
Independent Analytics – WordPress Analytics Plugin v2.15.5
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / translation / Command / TranslationPushCommand.php
independent-analytics / vendor / symfony / translation / Command Last commit date
TranslationPullCommand.php 1 month ago TranslationPushCommand.php 1 month ago TranslationTrait.php 2 years ago XliffLintCommand.php 1 month ago
TranslationPushCommand.php
147 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWPSCOPED\Symfony\Component\Translation\Command;
12
13 use IAWPSCOPED\Symfony\Component\Console\Attribute\AsCommand;
14 use IAWPSCOPED\Symfony\Component\Console\Command\Command;
15 use IAWPSCOPED\Symfony\Component\Console\Completion\CompletionInput;
16 use IAWPSCOPED\Symfony\Component\Console\Completion\CompletionSuggestions;
17 use IAWPSCOPED\Symfony\Component\Console\Exception\InvalidArgumentException;
18 use IAWPSCOPED\Symfony\Component\Console\Input\InputArgument;
19 use IAWPSCOPED\Symfony\Component\Console\Input\InputInterface;
20 use IAWPSCOPED\Symfony\Component\Console\Input\InputOption;
21 use IAWPSCOPED\Symfony\Component\Console\Output\OutputInterface;
22 use IAWPSCOPED\Symfony\Component\Console\Style\SymfonyStyle;
23 use IAWPSCOPED\Symfony\Component\Translation\Provider\FilteringProvider;
24 use IAWPSCOPED\Symfony\Component\Translation\Provider\TranslationProviderCollection;
25 use IAWPSCOPED\Symfony\Component\Translation\Reader\TranslationReaderInterface;
26 use IAWPSCOPED\Symfony\Component\Translation\TranslatorBag;
27 /**
28 * @author Mathieu Santostefano <msantostefano@protonmail.com>
29 * @internal
30 */
31 #[AsCommand(name: 'translation:push', description: 'Push translations to a given provider.')]
32 final class TranslationPushCommand extends Command
33 {
34 use TranslationTrait;
35 private $providers;
36 private $reader;
37 private array $transPaths;
38 private array $enabledLocales;
39 public function __construct(TranslationProviderCollection $providers, TranslationReaderInterface $reader, array $transPaths = [], array $enabledLocales = [])
40 {
41 $this->providers = $providers;
42 $this->reader = $reader;
43 $this->transPaths = $transPaths;
44 $this->enabledLocales = $enabledLocales;
45 parent::__construct();
46 }
47 public function complete(CompletionInput $input, CompletionSuggestions $suggestions) : void
48 {
49 if ($input->mustSuggestArgumentValuesFor('provider')) {
50 $suggestions->suggestValues($this->providers->keys());
51 return;
52 }
53 if ($input->mustSuggestOptionValuesFor('domains')) {
54 $provider = $this->providers->get($input->getArgument('provider'));
55 if ($provider && \method_exists($provider, 'getDomains')) {
56 $domains = $provider->getDomains();
57 $suggestions->suggestValues($domains);
58 }
59 return;
60 }
61 if ($input->mustSuggestOptionValuesFor('locales')) {
62 $suggestions->suggestValues($this->enabledLocales);
63 }
64 }
65 /**
66 * {@inheritdoc}
67 */
68 protected function configure()
69 {
70 $keys = $this->providers->keys();
71 $defaultProvider = 1 === \count($keys) ? $keys[0] : null;
72 $this->setDefinition([new InputArgument('provider', null !== $defaultProvider ? InputArgument::OPTIONAL : InputArgument::REQUIRED, 'The provider to push translations to.', $defaultProvider), new InputOption('force', null, InputOption::VALUE_NONE, 'Override existing translations with local ones (it will delete not synchronized messages).'), new InputOption('delete-missing', null, InputOption::VALUE_NONE, 'Delete translations available on provider but not locally.'), new InputOption('domains', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Specify the domains to push.'), new InputOption('locales', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Specify the locales to push.', $this->enabledLocales)])->setHelp(<<<'EOF'
73 The <info>%command.name%</> command pushes translations to the given provider. Only new
74 translations are pushed, existing ones are not overwritten.
75
76 You can overwrite existing translations by using the <comment>--force</> flag:
77
78 <info>php %command.full_name% --force provider</>
79
80 You can delete provider translations which are not present locally by using the <comment>--delete-missing</> flag:
81
82 <info>php %command.full_name% --delete-missing provider</>
83
84 Full example:
85
86 <info>php %command.full_name% provider --force --delete-missing --domains=messages --domains=validators --locales=en</>
87
88 This command pushes all translations associated with the <comment>messages</> and <comment>validators</> domains for the <comment>en</> locale.
89 Provider translations for the specified domains and locale are deleted if they're not present locally and overwritten if it's the case.
90 Provider translations for others domains and locales are ignored.
91 EOF
92 );
93 }
94 /**
95 * {@inheritdoc}
96 */
97 protected function execute(InputInterface $input, OutputInterface $output) : int
98 {
99 $provider = $this->providers->get($input->getArgument('provider'));
100 if (!$this->enabledLocales) {
101 throw new InvalidArgumentException(\sprintf('You must define "framework.translator.enabled_locales" or "framework.translator.providers.%s.locales" config key in order to work with translation providers.', \parse_url($provider, \PHP_URL_SCHEME)));
102 }
103 $io = new SymfonyStyle($input, $output);
104 $domains = $input->getOption('domains');
105 $locales = $input->getOption('locales');
106 $force = $input->getOption('force');
107 $deleteMissing = $input->getOption('delete-missing');
108 if (!$domains && $provider instanceof FilteringProvider) {
109 $domains = $provider->getDomains();
110 }
111 // Reading local translations must be done after retrieving the domains from the provider
112 // in order to manage only translations from configured domains
113 $localTranslations = $this->readLocalTranslations($locales, $domains, $this->transPaths);
114 if (!$domains) {
115 $domains = $this->getDomainsFromTranslatorBag($localTranslations);
116 }
117 if (!$deleteMissing && $force) {
118 $provider->write($localTranslations);
119 $io->success(\sprintf('All local translations has been sent to "%s" (for "%s" locale(s), and "%s" domain(s)).', \parse_url($provider, \PHP_URL_SCHEME), \implode(', ', $locales), \implode(', ', $domains)));
120 return 0;
121 }
122 $providerTranslations = $provider->read($domains, $locales);
123 if ($deleteMissing) {
124 $provider->delete($providerTranslations->diff($localTranslations));
125 $io->success(\sprintf('Missing translations on "%s" has been deleted (for "%s" locale(s), and "%s" domain(s)).', \parse_url($provider, \PHP_URL_SCHEME), \implode(', ', $locales), \implode(', ', $domains)));
126 // Read provider translations again, after missing translations deletion,
127 // to avoid push freshly deleted translations.
128 $providerTranslations = $provider->read($domains, $locales);
129 }
130 $translationsToWrite = $localTranslations->diff($providerTranslations);
131 if ($force) {
132 $translationsToWrite->addBag($localTranslations->intersect($providerTranslations));
133 }
134 $provider->write($translationsToWrite);
135 $io->success(\sprintf('%s local translations has been sent to "%s" (for "%s" locale(s), and "%s" domain(s)).', $force ? 'All' : 'New', \parse_url($provider, \PHP_URL_SCHEME), \implode(', ', $locales), \implode(', ', $domains)));
136 return 0;
137 }
138 private function getDomainsFromTranslatorBag(TranslatorBag $translatorBag) : array
139 {
140 $domains = [];
141 foreach ($translatorBag->getCatalogues() as $catalogue) {
142 $domains += $catalogue->getDomains();
143 }
144 return \array_unique($domains);
145 }
146 }
147