1 | <?php |
||
13 | class Writer |
||
14 | { |
||
15 | use Output; |
||
16 | |||
17 | /** @var Collection */ |
||
18 | protected $translations; |
||
19 | |||
20 | /** @var Spreadsheet */ |
||
21 | protected $spreadsheet; |
||
22 | |||
23 | /** @var Filesystem */ |
||
24 | protected $files; |
||
25 | |||
26 | /** @var Application */ |
||
27 | protected $app; |
||
28 | |||
29 | 1 | public function __construct(Spreadsheet $spreadsheet, Filesystem $files, Application $app) |
|
37 | |||
38 | 1 | public function setTranslations($translations) |
|
44 | |||
45 | 1 | public function write() |
|
56 | |||
57 | 1 | protected function writeFile($file, $items) |
|
69 | |||
70 | 1 | protected function groupTranslationsByFile() |
|
71 | { |
||
72 | 1 | $items = $this |
|
73 | ->translations |
||
74 | 1 | ->groupBy('sourceFile') |
|
75 | 1 | ->map(function ($fileTranslations) { |
|
76 | 1 | return $this->buildTranslationsForFile($fileTranslations); |
|
77 | 1 | }); |
|
78 | |||
79 | // flatten does not seem to work for every case. !!! refactor !!! |
||
80 | 1 | $result = []; |
|
81 | 1 | foreach ($items as $subitems) { |
|
82 | 1 | $result = array_merge($result, $subitems); |
|
83 | 1 | } |
|
84 | |||
85 | 1 | return new Collection($result); |
|
86 | } |
||
87 | |||
88 | 1 | protected function buildTranslationsForFile($fileTranslations) |
|
115 | } |
||
116 |