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 $path |
||
164 | * |
||
165 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
166 | */ |
||
167 | 132 | private function loadJsonTranslations(string $path): LocaleCollection |
|
182 | |||
183 | /** |
||
184 | * Get locale collection by group location. |
||
185 | * |
||
186 | * @param string $group |
||
187 | * @param mixed|null $default |
||
188 | * |
||
189 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection|null |
||
190 | */ |
||
191 | 102 | public function getCollection(string $group, $default = null): ?LocaleCollection |
|
195 | |||
196 | /** |
||
197 | * Get a locale translations from a group. |
||
198 | * |
||
199 | * @param string $group |
||
200 | * @param string $locale |
||
201 | * @param null $default |
||
202 | * |
||
203 | * @return \Arcanedev\LaravelLang\Entities\Locale|null |
||
204 | */ |
||
205 | 18 | public function getFrom(string $group, string $locale, $default = null): ?Locale |
|
215 | |||
216 | /** |
||
217 | * Get locale keys. |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | 12 | public function keys(): array |
|
236 | |||
237 | /** |
||
238 | * Get locales count. |
||
239 | * |
||
240 | * @return int |
||
241 | */ |
||
242 | 6 | public function count(): int |
|
246 | |||
247 | /* ----------------------------------------------------------------- |
||
248 | | Check Methods |
||
249 | | ----------------------------------------------------------------- |
||
250 | */ |
||
251 | |||
252 | /** |
||
253 | * Check if a translation group exists. |
||
254 | * |
||
255 | * @param string $group |
||
256 | * |
||
257 | * @return bool |
||
258 | */ |
||
259 | 24 | public function hasCollection(string $group): bool |
|
263 | |||
264 | /** |
||
265 | * Check if the given path is excluded. |
||
266 | * |
||
267 | * @param string $path |
||
268 | * |
||
269 | * @return bool |
||
270 | */ |
||
271 | 132 | private function isExcluded(string $path): bool |
|
275 | } |
||
276 |