1 | <?php |
||
17 | class TransManager implements TransManagerContract |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Properties |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * Lang directories paths. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $paths = []; |
||
30 | |||
31 | /** |
||
32 | * Translations collection. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $locales = []; |
||
37 | |||
38 | /** |
||
39 | * The filesystem instance. |
||
40 | * |
||
41 | * @var \Illuminate\Filesystem\Filesystem |
||
42 | */ |
||
43 | private $filesystem; |
||
44 | |||
45 | /** |
||
46 | * Excluded folders. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | private $excludedFolders = [ |
||
51 | 'script', |
||
52 | 'vendor', |
||
53 | ]; |
||
54 | |||
55 | /* ----------------------------------------------------------------- |
||
56 | | Constructor |
||
57 | | ----------------------------------------------------------------- |
||
58 | */ |
||
59 | |||
60 | /** |
||
61 | * Make TransManager instance. |
||
62 | * |
||
63 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
64 | * @param array $paths |
||
65 | */ |
||
66 | 132 | public function __construct(Filesystem $filesystem, array $paths) |
|
73 | |||
74 | /* ----------------------------------------------------------------- |
||
75 | | Getters & Setters |
||
76 | | ----------------------------------------------------------------- |
||
77 | */ |
||
78 | |||
79 | /** |
||
80 | * Get the translation paths. |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | 132 | public function getPaths(): array |
|
88 | |||
89 | /* ----------------------------------------------------------------- |
||
90 | | Main Methods |
||
91 | | ----------------------------------------------------------------- |
||
92 | */ |
||
93 | |||
94 | /** |
||
95 | * Load lang files. |
||
96 | */ |
||
97 | 132 | private function load(): void |
|
108 | |||
109 | /** |
||
110 | * Load translation files. |
||
111 | * |
||
112 | * @param string $dirPath |
||
113 | * |
||
114 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
115 | */ |
||
116 | 132 | private function loadTranslations(string $dirPath): LocaleCollection |
|
131 | |||
132 | /** |
||
133 | * Load the locale translation files. |
||
134 | * |
||
135 | * @param string $path |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | 132 | private function loadTranslationFiles(string $path): array |
|
159 | |||
160 | /** |
||
161 | * Load json translation files. |
||
162 | * |
||
163 | * @param string $dirPath |
||
164 | * |
||
165 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
166 | */ |
||
167 | 132 | private function loadJsonTranslations(string $dirPath): LocaleCollection |
|
187 | |||
188 | /** |
||
189 | * Get locale collection by group location. |
||
190 | * |
||
191 | * @param string $group |
||
192 | * @param mixed|null $default |
||
193 | * |
||
194 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection|null |
||
195 | */ |
||
196 | 102 | public function getCollection(string $group, $default = null): ?LocaleCollection |
|
200 | |||
201 | /** |
||
202 | * Get a locale translations from a group. |
||
203 | * |
||
204 | * @param string $group |
||
205 | * @param string $locale |
||
206 | * @param null $default |
||
207 | * |
||
208 | * @return \Arcanedev\LaravelLang\Entities\Locale|null |
||
209 | */ |
||
210 | 18 | public function getFrom(string $group, string $locale, $default = null): ?Locale |
|
220 | |||
221 | /** |
||
222 | * Get locale keys. |
||
223 | * |
||
224 | * @return array |
||
225 | */ |
||
226 | 12 | public function keys(): array |
|
241 | |||
242 | /** |
||
243 | * Get locales count. |
||
244 | * |
||
245 | * @return int |
||
246 | */ |
||
247 | 6 | public function count(): int |
|
251 | |||
252 | /* ----------------------------------------------------------------- |
||
253 | | Check Methods |
||
254 | | ----------------------------------------------------------------- |
||
255 | */ |
||
256 | |||
257 | /** |
||
258 | * Check if a translation group exists. |
||
259 | * |
||
260 | * @param string $group |
||
261 | * |
||
262 | * @return bool |
||
263 | */ |
||
264 | 24 | public function hasCollection(string $group): bool |
|
268 | |||
269 | /** |
||
270 | * Check if the given path is excluded. |
||
271 | * |
||
272 | * @param string $path |
||
273 | * |
||
274 | * @return bool |
||
275 | */ |
||
276 | 132 | private function isExcluded(string $path): bool |
|
280 | } |
||
281 |