1 | <?php |
||
11 | class Reader |
||
12 | { |
||
13 | /** |
||
14 | * Translation items. |
||
15 | * |
||
16 | * @var \Illuminate\Support\Collection |
||
17 | */ |
||
18 | protected $translations; |
||
19 | |||
20 | /** |
||
21 | * @var Application |
||
22 | */ |
||
23 | protected $app; |
||
24 | |||
25 | /** |
||
26 | * @var \Illuminate\Filesystem\Filesystem |
||
27 | */ |
||
28 | protected $files; |
||
29 | |||
30 | /** |
||
31 | * @var string specify locale that we need to scan. |
||
32 | * Returns all if no locale specified. |
||
33 | */ |
||
34 | private $locale; |
||
35 | |||
36 | /** |
||
37 | * @var TranslationsSheet |
||
38 | */ |
||
39 | protected $translationSheet; |
||
40 | |||
41 | 5 | /** |
|
42 | * Reader. |
||
43 | 5 | * |
|
44 | 5 | * @param Application $app |
|
45 | 5 | * @param Filesystem $files |
|
46 | */ |
||
47 | public function __construct(Application $app, Filesystem $files) |
||
52 | |||
53 | /** |
||
54 | * Set the translation sheets for reader. |
||
55 | * |
||
56 | * @param TranslationsSheet $translationSheet |
||
57 | * @return Reader |
||
58 | */ |
||
59 | public function setTranslationsSheet(TranslationsSheet $translationSheet) |
||
65 | |||
66 | /** |
||
67 | 4 | * Set reader locale. |
|
68 | * |
||
69 | * @param $locale |
||
70 | 4 | * @return $this |
|
71 | */ |
||
72 | public function setLocale($locale) |
||
78 | |||
79 | /** |
||
80 | * Scan modules, app and overridden packages lang |
||
81 | * and return all defined translations. |
||
82 | * |
||
83 | 4 | * @return Collection |
|
84 | * @return array |
||
85 | 4 | */ |
|
86 | 4 | public function scan() |
|
94 | |||
95 | /** |
||
96 | * Scan a directory. |
||
97 | * |
||
98 | * @param string $path to directory to scan |
||
99 | */ |
||
100 | 4 | protected function scanDirectory($path) |
|
114 | |||
115 | /** |
||
116 | * Scan overridden packages lang. |
||
117 | 4 | * |
|
118 | * @param $vendorsDirectory |
||
119 | 4 | */ |
|
120 | private function scanVendorDirectory($vendorsDirectory) |
||
129 | |||
130 | /** |
||
131 | * Load all directory file translation (multiple group) into translations collection. |
||
132 | * |
||
133 | * @param $directory |
||
134 | * @param $locale |
||
135 | * @param $namespace |
||
136 | */ |
||
137 | private function loadTranslationsInDirectory($directory, $locale, $namespace) |
||
149 | |||
150 | /** |
||
151 | 4 | * Load file translation (group) into translations collection. |
|
152 | 4 | * |
|
153 | 4 | * @param $locale |
|
154 | 4 | * @param $group |
|
155 | 4 | * @param $namespace |
|
156 | 4 | * @param $file |
|
157 | 4 | */ |
|
158 | 4 | private function loadTranslations($locale, $group, $namespace, $file) |
|
187 | |||
188 | 4 | /** |
|
189 | * Return a full lang key. |
||
190 | * |
||
191 | * @param $namespace |
||
192 | * @param $group |
||
193 | * @param $key |
||
194 | * @return string |
||
195 | */ |
||
196 | private function fullKey($namespace, $group, $key) |
||
203 | |||
204 | /** |
||
205 | * Return relative path of language file. |
||
206 | * |
||
207 | * @param $file |
||
208 | * @return mixed |
||
209 | */ |
||
210 | private function sourceFile($file) |
||
214 | 4 | ||
215 | 4 | /** |
|
216 | * Return relative path related to base_path(). |
||
217 | * |
||
218 | * @param $path |
||
219 | * @return string |
||
220 | */ |
||
221 | private function toRelative($path) |
||
228 | 4 | ||
229 | /** |
||
230 | 4 | * Determine if a found locale is requested for scanning. |
|
231 | * If $this->locale is not set, we assume that all the locales were requested. |
||
232 | * |
||
233 | * @param string $locale the locale to check |
||
234 | * @return bool |
||
235 | */ |
||
236 | private function requestedLocale($locale) |
||
244 | |||
245 | /** |
||
246 | * Return locale from directory |
||
247 | * ie. resources/lang/en -> en. |
||
248 | * |
||
249 | * @param $directory |
||
250 | * @return string |
||
251 | */ |
||
252 | private function getLocaleFromDirectory($directory) |
||
256 | |||
257 | /** |
||
258 | * Return true if it is the vendor directory. |
||
259 | * |
||
260 | * @param $directory |
||
261 | * @return bool |
||
262 | */ |
||
263 | private function isVendorDirectory($directory) |
||
267 | } |
||
268 |