-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslSynchCommand.php
87 lines (65 loc) · 3.14 KB
/
TranslSynchCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
declare(strict_types=1);
namespace Transl\Commands;
use Illuminate\Support\Arr;
use Illuminate\Console\Command;
use Transl\Commands\TranslPullCommand;
use Transl\Commands\TranslPushCommand;
class TranslSynchCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = '
transl:synch
{--project= : The configured project to target (should be the `auth_key` or the `name` of a project defined in `config(transl.projects)`)}
{--branch= : The branch on the defined project to target (if the value provided does not exist, it will be created on Transl.me)}
{--conflicts= : The strategy to be used to resolve conflicts (see the enum `\Transl\Config\Enums\BranchingConflictResolutionEnum` for allowed values)}
{--only-locales=* : Will pull only translation lines from the specified locales (expects a comma separated list or providing this option multiple times)}
{--only-groups=* : Will pull only translation lines from the specified groups (expects a comma separated list or providing this option multiple times)}
{--only-namespaces=* : Will pull only translation lines from the specified namespaces (expects a comma separated list or providing this option multiple times)}
{--except-locales=* : Will pull only translation lines NOT from the specified locales (expects a comma separated list or providing this option multiple times)}
{--except-groups=* : Will pull only translation lines NOT from the specified groups (expects a comma separated list or providing this option multiple times)}
{--except-namespaces=* : Will pull only translation lines NOT from the specified namespaces (expects a comma separated list or providing this option multiple times)}
';
/**
* The console command description.
*
* @var string
*/
protected $description = "Pulls then pushes the defined project's translation lines to Transl.me";
/**
* Execute the console command.
*/
public function handle(): int
{
$options = $this->providedOptions();
$pulled = $this->call(TranslPullCommand::class, $options);
$this->newLine(3);
if ($pulled !== self::SUCCESS) {
$this->outputFailureMessage();
return self::FAILURE;
}
$pushed = $this->call(TranslPushCommand::class, Arr::except($options, ['--conflicts']));
$this->newLine(3);
if ($pushed !== self::SUCCESS) {
$this->outputFailureMessage();
return self::FAILURE;
}
$this->components->info('Translation lines synchronized successfully!');
return self::SUCCESS;
}
protected function providedOptions(): array
{
return collect($this->options())->reduce(static function (array $acc, mixed $value, string $key) {
$acc["--{$key}"] = $value;
return $acc;
}, []);
}
protected function outputFailureMessage(): void
{
$this->components->error('Failed synchronizing the translation lines.');
}
}