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