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\Processors; |
21
|
|
|
|
22
|
|
|
use Helldar\Contracts\LangPublisher\Processor; |
23
|
|
|
use Helldar\Contracts\LangPublisher\Provider; |
24
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Has; |
25
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Keyable; |
26
|
|
|
use Helldar\LaravelLangPublisher\Concerns\Paths; |
27
|
|
|
use Helldar\Support\Facades\Helpers\Arr; |
28
|
|
|
use Illuminate\Support\Str; |
29
|
|
|
|
30
|
|
|
abstract class BaseProcessor implements Processor |
31
|
|
|
{ |
32
|
|
|
use Has; |
33
|
|
|
use Keyable; |
34
|
|
|
use Paths; |
35
|
|
|
|
36
|
|
|
/** @var Provider */ |
37
|
|
|
protected $provider; |
38
|
|
|
|
39
|
|
|
protected $force = false; |
40
|
|
|
|
41
|
|
|
protected $locales = []; |
42
|
|
|
|
43
|
|
|
protected $source_keys = []; |
44
|
|
|
|
45
|
|
|
protected $translated = []; |
46
|
|
|
|
47
|
|
|
/** @var \Helldar\Contracts\LangPublisher\Comparator */ |
48
|
|
|
protected $comparator; |
49
|
|
|
|
50
|
|
|
public function __construct(array $locales, bool $force = false) |
51
|
|
|
{ |
52
|
|
|
$this->locales = $this->prepareLocales($locales); |
53
|
|
|
|
54
|
|
|
$this->force = $force; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function compare(): array |
58
|
|
|
{ |
59
|
|
|
return (new $this->comparator($this->source_keys, $this->translated, $this->force))->get(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function set(array &$array, string $key, array $values): void |
63
|
|
|
{ |
64
|
|
|
$loaded = $array[$key] ?? []; |
65
|
|
|
|
66
|
|
|
$array[$key] = Arr::merge($loaded, $values); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function preparePath(string $path, string $locale): string |
70
|
|
|
{ |
71
|
|
|
return Str::replace('{locale}', $locale, $path); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected function prepareLocales(array $locales): array |
75
|
|
|
{ |
76
|
|
|
return $locales; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|