1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Catalogue; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
15
|
|
|
use Symfony\Component\Translation\Writer\TranslationWriter; |
16
|
|
|
use Translation\Bundle\Model\Configuration; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Write catalogues back to disk. |
20
|
|
|
* |
21
|
|
|
* This should be considered as a "WriteToCache" service. |
22
|
|
|
* |
23
|
|
|
* @author Tobias Nyholm <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class CatalogueWriter |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var TranslationWriter |
29
|
|
|
*/ |
30
|
|
|
private $writer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $defaultLocale; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param TranslationWriter $writer |
39
|
|
|
* @param string $defaultLocale |
40
|
|
|
*/ |
41
|
6 |
|
public function __construct( |
42
|
|
|
TranslationWriter $writer, |
43
|
|
|
$defaultLocale |
44
|
|
|
) { |
45
|
6 |
|
$this->writer = $writer; |
46
|
6 |
|
$this->defaultLocale = $defaultLocale; |
47
|
6 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Configuration $config |
51
|
|
|
* @param MessageCatalogue[] $catalogues |
52
|
|
|
*/ |
53
|
1 |
|
public function writeCatalogues(Configuration $config, array $catalogues) |
54
|
|
|
{ |
55
|
1 |
|
foreach ($catalogues as $catalogue) { |
56
|
1 |
|
$this->writer->writeTranslations( |
57
|
1 |
|
$catalogue, |
58
|
1 |
|
$config->getOutputFormat(), |
59
|
|
|
[ |
60
|
1 |
|
'path' => $config->getOutputDir(), |
61
|
1 |
|
'default_locale' => $this->defaultLocale, |
62
|
1 |
|
'xliff_version' => $config->getXliffVersion(), |
63
|
|
|
] |
64
|
1 |
|
); |
65
|
1 |
|
} |
66
|
1 |
|
} |
67
|
|
|
} |
68
|
|
|
|