1 | <?php |
||
18 | class TransManager implements TransManagerContract |
||
19 | { |
||
20 | /* ----------------------------------------------------------------- |
||
21 | | Properties |
||
22 | | ----------------------------------------------------------------- |
||
23 | */ |
||
24 | |||
25 | /** |
||
26 | * Lang directories paths. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $paths = []; |
||
31 | |||
32 | /** |
||
33 | * Translations collection. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $locales = []; |
||
38 | |||
39 | /** |
||
40 | * The filesystem instance. |
||
41 | * |
||
42 | * @var \Illuminate\Filesystem\Filesystem |
||
43 | */ |
||
44 | private $filesystem; |
||
45 | |||
46 | /** |
||
47 | * Excluded folders. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | private $excludedFolders = ['script', 'vendor']; |
||
52 | |||
53 | /* ----------------------------------------------------------------- |
||
54 | | Constructor |
||
55 | | ----------------------------------------------------------------- |
||
56 | */ |
||
57 | |||
58 | /** |
||
59 | 40 | * Make TransManager instance. |
|
60 | * |
||
61 | 40 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
|
62 | 40 | * @param array $paths |
|
63 | */ |
||
64 | 40 | public function __construct(Filesystem $filesystem, array $paths) |
|
71 | |||
72 | /* ----------------------------------------------------------------- |
||
73 | | Getters & Setters |
||
74 | | ----------------------------------------------------------------- |
||
75 | */ |
||
76 | |||
77 | 40 | /** |
|
78 | * Get the translation paths. |
||
79 | 40 | * |
|
80 | * @return array |
||
81 | */ |
||
82 | public function getPaths(): array |
||
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Main Methods |
||
89 | | ----------------------------------------------------------------- |
||
90 | 40 | */ |
|
91 | |||
92 | 40 | /** |
|
93 | 40 | * Load lang files. |
|
94 | */ |
||
95 | 40 | private function load(): void |
|
101 | |||
102 | /** |
||
103 | * Load directories. |
||
104 | 40 | * |
|
105 | * @param string $dirPath |
||
106 | 40 | * |
|
107 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
108 | 40 | */ |
|
109 | 40 | private function loadDirectories($dirPath): LocaleCollection |
|
125 | |||
126 | /** |
||
127 | * Load the locale translation files. |
||
128 | 40 | * |
|
129 | * @param string $path |
||
130 | 40 | * |
|
131 | * @return array |
||
132 | 40 | */ |
|
133 | private function loadLocaleFiles(string $path): array |
||
151 | |||
152 | /** |
||
153 | * Get locale collection by group location. |
||
154 | * |
||
155 | 30 | * @param string $group |
|
156 | * @param mixed|null $default |
||
157 | 30 | * |
|
158 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection|null |
||
159 | */ |
||
160 | public function getCollection(string $group, $default = null): ?LocaleCollection |
||
164 | |||
165 | /** |
||
166 | * Get a locale translations from a group. |
||
167 | * |
||
168 | * @param string $group |
||
169 | 6 | * @param string $locale |
|
170 | * @param null $default |
||
171 | 6 | * |
|
172 | 2 | * @return \Arcanedev\LaravelLang\Entities\Locale|null |
|
173 | */ |
||
174 | 4 | public function getFrom(string $group, string $locale, $default = null): ?Locale |
|
184 | 4 | ||
185 | /** |
||
186 | * Get locale keys. |
||
187 | 4 | * |
|
188 | 4 | * @return array |
|
189 | 4 | */ |
|
190 | public function keys(): array |
||
205 | 2 | ||
206 | /** |
||
207 | 2 | * Get locales count. |
|
208 | * |
||
209 | * @return int |
||
210 | */ |
||
211 | public function count(): int |
||
215 | |||
216 | /* ----------------------------------------------------------------- |
||
217 | | Check Methods |
||
218 | | ----------------------------------------------------------------- |
||
219 | */ |
||
220 | |||
221 | /** |
||
222 | 8 | * Check if a translation group exists. |
|
223 | * |
||
224 | 8 | * @param string $group |
|
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | public function hasCollection(string $group): bool |
||
232 | |||
233 | /** |
||
234 | * Check if the given path is excluded. |
||
235 | * |
||
236 | * @param string $path |
||
237 | * |
||
238 | * @return bool |
||
239 | */ |
||
240 | private function isExcluded(string $path): bool |
||
244 | } |
||
245 |