1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the "andrey-helldar/laravel-lang-publisher" project. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @author Andrey Helldar <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @copyright 2021 Andrey Helldar |
12
|
|
|
* |
13
|
|
|
* @license MIT |
14
|
|
|
* |
15
|
|
|
* @see https://github.com/andrey-helldar/laravel-lang-publisher |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Helldar\LaravelLangPublisher\Concerns; |
21
|
|
|
|
22
|
|
|
use Helldar\LaravelLangPublisher\Facades\Helpers\Locales; |
23
|
|
|
use Helldar\Support\Facades\Helpers\Arr; |
24
|
|
|
use Helldar\Support\Facades\Helpers\Str; |
25
|
|
|
|
26
|
|
|
trait Ask |
27
|
|
|
{ |
28
|
62 |
|
protected function getLocales(): array |
29
|
|
|
{ |
30
|
62 |
|
if ($locales = $this->argument('locales')) { |
|
|
|
|
31
|
62 |
|
return $this->resolveSelectedLocales($locales); |
32
|
|
|
} |
33
|
|
|
|
34
|
6 |
|
return $this->askLocales($this->getMethod()); |
35
|
|
|
} |
36
|
|
|
|
37
|
6 |
|
protected function askLocales(string $method): array |
38
|
|
|
{ |
39
|
6 |
|
$locales = $this->confirm("Do you want to $method all localizations?") ? $this->getAllLocales() : $this->selectLocales($method); |
|
|
|
|
40
|
|
|
|
41
|
6 |
|
return $this->resolveSelectedLocales($locales); |
42
|
|
|
} |
43
|
|
|
|
44
|
6 |
|
protected function selectLocales(string $method) |
45
|
|
|
{ |
46
|
6 |
|
return $this->choice("Select localizations to $method (specify the necessary localizations separated by commas):", $this->getAllLocales(), null, null, true); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
62 |
|
protected function resolveSelectedLocales($locales): array |
50
|
|
|
{ |
51
|
62 |
|
$locales = Arr::wrap($locales); |
52
|
|
|
|
53
|
62 |
|
return $this->validatedLocales($locales); |
54
|
|
|
} |
55
|
|
|
|
56
|
6 |
|
protected function getMethod(): string |
57
|
|
|
{ |
58
|
6 |
|
$name = class_basename(static::class); |
59
|
|
|
|
60
|
6 |
|
return Str::lower($name); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
62 |
|
protected function validatedLocales(array $locales): array |
64
|
|
|
{ |
65
|
62 |
|
foreach ($locales as $locale) { |
66
|
62 |
|
Locales::validate($locale); |
67
|
|
|
} |
68
|
|
|
|
69
|
62 |
|
return $locales; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|