|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelLang\Commands; |
|
6
|
|
|
|
|
7
|
|
|
use Arcanedev\LaravelLang\Contracts\TransPublisher; |
|
8
|
|
|
use Arcanedev\LaravelLang\Exceptions\LangPublishException; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class PublishCommand |
|
12
|
|
|
* |
|
13
|
|
|
* @package Arcanedev\LaravelLang\Commands |
|
14
|
|
|
* @author ARCANEDEV <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class PublishCommand extends AbstractCommand |
|
17
|
|
|
{ |
|
18
|
|
|
/* ----------------------------------------------------------------- |
|
19
|
|
|
| Properties |
|
20
|
|
|
| ----------------------------------------------------------------- |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The name and signature of the console command. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $signature = 'trans:publish |
|
29
|
|
|
{locale : The language to publish the translations.} |
|
30
|
|
|
{--force : Force to override the translations} |
|
31
|
|
|
{--inline : Publish the inline translations}'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* The console command description. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $description = 'Publish the [locale] translations.'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The TransPublisher instance. |
|
42
|
|
|
* |
|
43
|
|
|
* @var \Arcanedev\LaravelLang\Contracts\TransPublisher |
|
44
|
|
|
*/ |
|
45
|
|
|
private $publisher; |
|
46
|
|
|
|
|
47
|
|
|
/* ----------------------------------------------------------------- |
|
48
|
|
|
| Constructor |
|
49
|
|
|
| ----------------------------------------------------------------- |
|
50
|
|
|
*/ |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Create a new console command instance. |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Arcanedev\LaravelLang\Contracts\TransPublisher $publisher |
|
56
|
|
|
*/ |
|
57
|
42 |
|
public function __construct(TransPublisher $publisher) |
|
58
|
|
|
{ |
|
59
|
42 |
|
$this->publisher = $publisher; |
|
60
|
42 |
|
$this->name = 'trans:publish'; |
|
61
|
|
|
|
|
62
|
42 |
|
parent::__construct(); |
|
63
|
42 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/* ----------------------------------------------------------------- |
|
66
|
|
|
| Main Methods |
|
67
|
|
|
| ----------------------------------------------------------------- |
|
68
|
|
|
*/ |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Execute the console command. |
|
72
|
|
|
*/ |
|
73
|
30 |
|
public function handle(): void |
|
74
|
|
|
{ |
|
75
|
30 |
|
$this->copyright(); |
|
76
|
|
|
|
|
77
|
30 |
|
$locale = (string) $this->argument('locale'); |
|
78
|
|
|
|
|
79
|
30 |
|
if ($this->publisher->isDefault($locale)) { |
|
80
|
6 |
|
$this->info("The locale [{$locale}] is a default lang and it's shipped with laravel."); |
|
81
|
6 |
|
$this->line(''); |
|
82
|
6 |
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
24 |
|
$this->publish($locale, [ |
|
86
|
24 |
|
'force' => (bool) $this->option('force'), |
|
87
|
24 |
|
'inline' => (bool) $this->option('inline'), |
|
88
|
|
|
]); |
|
89
|
|
|
|
|
90
|
24 |
|
$this->line(''); |
|
91
|
24 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/* ----------------------------------------------------------------- |
|
94
|
|
|
| Other Methods |
|
95
|
|
|
| ----------------------------------------------------------------- |
|
96
|
|
|
*/ |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Publish the translations. |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $locale |
|
102
|
|
|
* @param array $options |
|
103
|
|
|
*/ |
|
104
|
24 |
|
private function publish(string $locale, array $options): void |
|
105
|
|
|
{ |
|
106
|
24 |
|
$this->info("Publishing the [{$locale}] translations..."); |
|
107
|
|
|
|
|
108
|
24 |
|
$results = $this->publisher->publish($locale, $options); |
|
109
|
|
|
|
|
110
|
24 |
|
$this->showResults(['Published translations'], $results['published']); |
|
111
|
24 |
|
$this->showResults(['Skipped translations'], $results['skipped']); |
|
112
|
24 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Show the results. |
|
116
|
|
|
* |
|
117
|
|
|
* @param array $headers |
|
118
|
|
|
* @param array $results |
|
119
|
|
|
*/ |
|
120
|
24 |
|
public function showResults(array $headers, array $results): void |
|
121
|
|
|
{ |
|
122
|
24 |
|
if (empty($results)) |
|
123
|
24 |
|
return; |
|
124
|
|
|
|
|
125
|
|
|
$this->table($headers, array_map(function($result) { |
|
126
|
24 |
|
return [$result]; |
|
127
|
24 |
|
}, $results)); |
|
128
|
24 |
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|