1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nikaia\TranslationSheet; |
4
|
|
|
|
5
|
|
|
use Nikaia\TranslationSheet\Commands\Output; |
6
|
|
|
use Nikaia\TranslationSheet\Sheet\TranslationsSheet; |
7
|
|
|
use Nikaia\TranslationSheet\Translation\Reader; |
8
|
|
|
use Nikaia\TranslationSheet\Translation\Transformer; |
9
|
|
|
|
10
|
|
|
class Pusher |
11
|
|
|
{ |
12
|
|
|
use Output; |
13
|
|
|
|
14
|
|
|
/** @var Reader */ |
15
|
|
|
protected $reader; |
16
|
|
|
|
17
|
|
|
/** @var TranslationsSheet */ |
18
|
|
|
protected $translationsSheet; |
19
|
|
|
|
20
|
|
|
/** @var Transformer */ |
21
|
|
|
protected $transformer; |
22
|
|
|
|
23
|
|
|
public function __construct(Reader $reader, TranslationsSheet $translationsSheet, Transformer $transformer) |
24
|
|
|
{ |
25
|
|
|
$this->reader = $reader; |
26
|
|
|
$this->translationsSheet = $translationsSheet; |
27
|
|
|
$this->transformer = $transformer; |
28
|
|
|
|
29
|
|
|
$this->nullOutput(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function push() |
33
|
|
|
{ |
34
|
|
|
$this->output->writeln('<comment>Scanning languages files</comment>'); |
35
|
|
|
$translations = $this->getScannedAndTransformedTranslations(); |
36
|
|
|
|
37
|
|
|
$this->output->writeln('<comment>Preparing spreasheet for new write operation</comment>'); |
38
|
|
|
$this->translationsSheet->prepareForWrite(); |
39
|
|
|
|
40
|
|
|
$this->output->writeln('<comment>Updating header</comment>'); |
41
|
|
|
$this->translationsSheet->updateHeaderRow(); |
42
|
|
|
|
43
|
|
|
$this->output->writeln('<comment>Writing translations in the spreadsheet</comment>'); |
44
|
|
|
$this->translationsSheet->writeTranslations($translations->toArray()); |
45
|
|
|
|
46
|
|
|
$this->output->writeln('<comment>Styling document</comment>'); |
47
|
|
|
$this->translationsSheet->styleDocument(); |
48
|
|
|
|
49
|
|
|
$this->output->writeln('<info>Done</info>.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getScannedAndTransformedTranslations() |
53
|
|
|
{ |
54
|
|
|
return $this->transformer |
55
|
|
|
->setLocales($this->translationsSheet->getSpreadsheet()->getLocales()) |
56
|
|
|
->transform($this->reader->scan()); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|