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 | * Make TransManager instance. |
||
60 | * |
||
61 | * @param \Illuminate\Filesystem\Filesystem $filesystem |
||
62 | * @param array $paths |
||
63 | */ |
||
64 | 120 | public function __construct(Filesystem $filesystem, array $paths) |
|
71 | |||
72 | /* ----------------------------------------------------------------- |
||
73 | | Getters & Setters |
||
74 | | ----------------------------------------------------------------- |
||
75 | */ |
||
76 | |||
77 | /** |
||
78 | * Get the translation paths. |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | 120 | public function getPaths(): array |
|
86 | |||
87 | /* ----------------------------------------------------------------- |
||
88 | | Main Methods |
||
89 | | ----------------------------------------------------------------- |
||
90 | */ |
||
91 | |||
92 | /** |
||
93 | * Load lang files. |
||
94 | */ |
||
95 | 120 | private function load(): void |
|
101 | |||
102 | /** |
||
103 | * Load directories. |
||
104 | * |
||
105 | * @param string $dirPath |
||
106 | * |
||
107 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection |
||
108 | */ |
||
109 | 120 | private function loadDirectories($dirPath): LocaleCollection |
|
125 | |||
126 | /** |
||
127 | * Load the locale translation files. |
||
128 | * |
||
129 | * @param string $path |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | 120 | private function loadLocaleFiles(string $path): array |
|
151 | |||
152 | /** |
||
153 | * Get locale collection by group location. |
||
154 | * |
||
155 | * @param string $group |
||
156 | * @param mixed|null $default |
||
157 | * |
||
158 | * @return \Arcanedev\LaravelLang\Entities\LocaleCollection|null |
||
159 | */ |
||
160 | 90 | public function getCollection(string $group, $default = null): ?LocaleCollection |
|
164 | |||
165 | /** |
||
166 | * Get a locale translations from a group. |
||
167 | * |
||
168 | * @param string $group |
||
169 | * @param string $locale |
||
170 | * @param null $default |
||
171 | * |
||
172 | * @return \Arcanedev\LaravelLang\Entities\Locale|null |
||
173 | */ |
||
174 | 18 | public function getFrom(string $group, string $locale, $default = null): ?Locale |
|
184 | |||
185 | /** |
||
186 | * Get locale keys. |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | 12 | public function keys(): array |
|
205 | |||
206 | /** |
||
207 | * Get locales count. |
||
208 | * |
||
209 | * @return int |
||
210 | */ |
||
211 | 6 | public function count(): int |
|
215 | |||
216 | /* ----------------------------------------------------------------- |
||
217 | | Check Methods |
||
218 | | ----------------------------------------------------------------- |
||
219 | */ |
||
220 | |||
221 | /** |
||
222 | * Check if a translation group exists. |
||
223 | * |
||
224 | * @param string $group |
||
225 | * |
||
226 | * @return bool |
||
227 | */ |
||
228 | 24 | 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 | 120 | private function isExcluded(string $path): bool |
|
244 | } |
||
245 |