|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\Generators; |
|
6
|
|
|
|
|
7
|
|
|
use Mariuzzo\LaravelJsLocalization\Generators\LangJsGenerator as BaseLangJsGenerator; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The LangJsGenerator class. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Rubens Mariuzzo <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class LangJsGenerator extends BaseLangJsGenerator |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Return all language messages. |
|
18
|
|
|
* |
|
19
|
|
|
* @return array |
|
20
|
|
|
* |
|
21
|
|
|
* @throws \Exception |
|
22
|
|
|
*/ |
|
23
|
|
|
protected function getMessages() |
|
24
|
|
|
{ |
|
25
|
|
|
$messages = []; |
|
26
|
|
|
|
|
27
|
|
|
foreach (array_merge(array_values(app('translation.loader')->namespaces()), [$this->sourcePath]) as $directory) { |
|
|
|
|
|
|
28
|
|
|
foreach ($this->file->allFiles($directory) as $file) { |
|
29
|
|
|
$path = substr($file->getPath(), 0, strrpos($file->getPath(), DIRECTORY_SEPARATOR)); |
|
30
|
|
|
$namespace = array_search($path, app('translation.loader')->namespaces()); |
|
31
|
|
|
|
|
32
|
|
|
$pathName = $file->getRelativePathName(); |
|
33
|
|
|
$extension = $file->getExtension(); |
|
34
|
|
|
if (! in_array($extension, ['json', 'php'])) { |
|
35
|
|
|
continue; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($this->isMessagesExcluded($pathName)) { |
|
39
|
|
|
continue; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$key = substr($pathName, 0, -4); |
|
43
|
|
|
$key = str_replace('\\', '.', $key); |
|
44
|
|
|
$key = str_replace('/', '.', $key); |
|
45
|
|
|
|
|
46
|
|
|
if ($namespace) { |
|
47
|
|
|
$key = substr($key, 0, strpos($key, '.')+1).str_replace('/', '.', $namespace).'::'.substr($key, strpos($key, '.')+1); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (starts_with($key, 'vendor')) { |
|
51
|
|
|
$key = $this->getVendorKey($key); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($extension == 'php') { |
|
55
|
|
|
$messages[$key] = include $file->getRealPath(); |
|
56
|
|
|
} else { |
|
57
|
|
|
$key = $key.$this->stringsDomain; |
|
58
|
|
|
$fileContent = file_get_contents($file->getRealPath()); |
|
59
|
|
|
$messages[$key] = json_decode($fileContent, true); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$this->sortMessages($messages); |
|
66
|
|
|
|
|
67
|
|
|
return $messages; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private function getVendorKey($key) |
|
71
|
|
|
{ |
|
72
|
|
|
$keyParts = explode('.', $key, 4); |
|
73
|
|
|
unset($keyParts[0]); |
|
74
|
|
|
|
|
75
|
|
|
return $keyParts[2] .'.'. $keyParts[1] . '::' . $keyParts[3]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.