|
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
|
1 |
|
public function __construct(Reader $reader, TranslationsSheet $translationsSheet, Transformer $transformer) |
|
24
|
|
|
{ |
|
25
|
1 |
|
$this->reader = $reader; |
|
26
|
1 |
|
$this->translationsSheet = $translationsSheet; |
|
27
|
1 |
|
$this->transformer = $transformer; |
|
28
|
|
|
|
|
29
|
1 |
|
$this->nullOutput(); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function push() |
|
33
|
|
|
{ |
|
34
|
1 |
|
$this->output->writeln('<comment>Scanning languages files</comment>'); |
|
35
|
1 |
|
$translations = $this->getScannedAndTransformedTranslations(); |
|
36
|
|
|
|
|
37
|
1 |
|
$this->output->writeln('<comment>Preparing spreasheet for new write operation</comment>'); |
|
38
|
1 |
|
$this->translationsSheet->prepareForWrite(); |
|
39
|
|
|
|
|
40
|
1 |
|
$this->output->writeln('<comment>Updating header</comment>'); |
|
41
|
1 |
|
$this->translationsSheet->updateHeaderRow(); |
|
42
|
|
|
|
|
43
|
1 |
|
$this->output->writeln('<comment>Writing translations in the spreadsheet</comment>'); |
|
44
|
1 |
|
$this->translationsSheet->writeTranslations($translations->toArray()); |
|
45
|
|
|
|
|
46
|
1 |
|
$this->output->writeln('<comment>Styling document</comment>'); |
|
47
|
1 |
|
$this->translationsSheet->styleDocument(); |
|
48
|
|
|
|
|
49
|
1 |
|
$this->output->writeln('<info>Done</info>.'); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function getScannedAndTransformedTranslations() |
|
53
|
|
|
{ |
|
54
|
1 |
|
return $this->transformer |
|
55
|
1 |
|
->setLocales($this->translationsSheet->getSpreadsheet()->getLocales()) |
|
56
|
1 |
|
->transform($this->reader->scan()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|