1 | <?php |
||
9 | class Reader |
||
10 | { |
||
11 | /** |
||
12 | * Translation items. |
||
13 | * |
||
14 | * @var \Illuminate\Support\Collection |
||
15 | */ |
||
16 | protected $translations; |
||
17 | |||
18 | /** |
||
19 | * @var Application |
||
20 | */ |
||
21 | protected $app; |
||
22 | |||
23 | /** |
||
24 | * @var \Illuminate\Filesystem\Filesystem |
||
25 | */ |
||
26 | protected $files; |
||
27 | |||
28 | /** |
||
29 | * @var string specify locale that we need to scan. |
||
30 | * Returns all if no locale specified. |
||
31 | */ |
||
32 | private $locale; |
||
33 | |||
34 | /** |
||
35 | * Reader. |
||
36 | * |
||
37 | * @param Application $app |
||
38 | * @param Filesystem $files |
||
39 | */ |
||
40 | 2 | public function __construct(Application $app, Filesystem $files) |
|
45 | |||
46 | /** |
||
47 | * Set reader locale. |
||
48 | * |
||
49 | * @param $locale |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function setLocale($locale) |
||
58 | |||
59 | /** |
||
60 | * Scan modules, app and overridden packages lang |
||
61 | * and return all defined translations. |
||
62 | * |
||
63 | * @return Collection |
||
64 | * @return array |
||
65 | */ |
||
66 | 1 | public function scan() |
|
76 | |||
77 | /** |
||
78 | * Scan a directory. |
||
79 | * |
||
80 | * @param string $path to directory to scan |
||
81 | */ |
||
82 | 1 | protected function scanDirectory($path) |
|
92 | |||
93 | /** |
||
94 | * Scan overridden packages lang. |
||
95 | * |
||
96 | * @param $vendorsDirectory |
||
97 | */ |
||
98 | 1 | private function scanVendorDirectory($vendorsDirectory) |
|
107 | |||
108 | /** |
||
109 | * Load all directory file translation (multiple group) into translations collection. |
||
110 | * |
||
111 | * @param $directory |
||
112 | * @param $locale |
||
113 | * @param $namespace |
||
114 | */ |
||
115 | 1 | private function loadTranslationsInDirectory($directory, $locale, $namespace) |
|
127 | |||
128 | /** |
||
129 | * Load file translation (group) into translations collection. |
||
130 | * |
||
131 | * @param $locale |
||
132 | * @param $group |
||
133 | * @param $namespace |
||
134 | * @param $file |
||
135 | */ |
||
136 | 1 | private function loadTranslations($locale, $group, $namespace, $file) |
|
161 | |||
162 | /** |
||
163 | * Return a full lang key. |
||
164 | * |
||
165 | * @param $namespace |
||
166 | * @param $group |
||
167 | * @param $key |
||
168 | * @return string |
||
169 | */ |
||
170 | 1 | private function fullKey($namespace, $group, $key) |
|
177 | |||
178 | /** |
||
179 | * Return relative path of language file. |
||
180 | * |
||
181 | * @param $file |
||
182 | * @return mixed |
||
183 | */ |
||
184 | 1 | private function sourceFile($file) |
|
188 | |||
189 | /** |
||
190 | * Return relative path related to base_path(). |
||
191 | * |
||
192 | * @param $path |
||
193 | * @return string |
||
194 | */ |
||
195 | 1 | private function toRelative($path) |
|
202 | |||
203 | /** |
||
204 | * Determine if a found locale is requested for scanning. |
||
205 | * If $this->locale is not set, we assume that all the locales were requested. |
||
206 | * |
||
207 | * @param string $locale the locale to check |
||
208 | * @return bool |
||
209 | */ |
||
210 | 1 | private function requestedLocale($locale) |
|
218 | |||
219 | /** |
||
220 | * Return locale from directory |
||
221 | * ie. resources/lang/en -> en. |
||
222 | * |
||
223 | * @param $directory |
||
224 | * @return string |
||
225 | */ |
||
226 | 1 | private function getLocaleFromDirectory($directory) |
|
230 | |||
231 | /** |
||
232 | * Return true if it is the vendor directory. |
||
233 | * |
||
234 | * @param $directory |
||
235 | * @return bool |
||
236 | */ |
||
237 | 2 | private function isVendorDirectory($directory) |
|
241 | } |
||
242 |