1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helldar\LaravelLangPublisher\Support; |
4
|
|
|
|
5
|
|
|
use Helldar\PrettyArray\Contracts\Caseable; |
6
|
|
|
use Illuminate\Support\Facades\Config as IlluminateConfig; |
7
|
|
|
|
8
|
|
|
final class Config |
9
|
|
|
{ |
10
|
|
|
public const KEY = 'lang-publisher'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Getting a link to the folder with the source localization files. |
14
|
|
|
* |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
48 |
|
public function getVendorPath(): string |
18
|
|
|
{ |
19
|
48 |
|
return realpath(__DIR__ . '/../../vendor/caouecs/laravel-lang/src'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Getting the default localization name. |
24
|
|
|
* |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
12 |
|
public function getLocale(): string |
28
|
|
|
{ |
29
|
12 |
|
return IlluminateConfig::get('app.locale') |
30
|
12 |
|
?: IlluminateConfig::get('app.fallback_locale', 'en'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Getting the fallback localization name. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
6 |
|
public function getFallbackLocale(): string |
39
|
|
|
{ |
40
|
6 |
|
return IlluminateConfig::get('app.fallback_locale', 'en'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Will array alignment be applied. |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
12 |
|
public function isAlignment(): bool |
49
|
|
|
{ |
50
|
12 |
|
return (bool) $this->config('alignment', true); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Returns an array of exceptions set by the developer |
55
|
|
|
* when installing and updating localizations. |
56
|
|
|
* |
57
|
|
|
* @param string $key |
58
|
|
|
* @param array $default |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
12 |
|
public function getExclude(string $key, array $default = []): array |
63
|
|
|
{ |
64
|
12 |
|
$exclude = $this->config('exclude', []); |
65
|
|
|
|
66
|
12 |
|
return $exclude[$key] ?? $default; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the key mapping label. |
71
|
|
|
* |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
12 |
|
public function getCase(): int |
75
|
|
|
{ |
76
|
12 |
|
return $this->config('case', Caseable::NO_CASE); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Determines what type of files to use when updating language files. |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
12 |
|
public function isInline(): bool |
85
|
|
|
{ |
86
|
12 |
|
return $this->config('inline', false); |
87
|
|
|
} |
88
|
|
|
|
89
|
12 |
|
protected function config(string $key, $default = null) |
90
|
|
|
{ |
91
|
12 |
|
$key = $this->key($key); |
92
|
|
|
|
93
|
12 |
|
return IlluminateConfig::get($key, $default); |
94
|
|
|
} |
95
|
|
|
|
96
|
12 |
|
protected function key(string $key): string |
97
|
|
|
{ |
98
|
12 |
|
return self::KEY . '.' . $key; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|