1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Itkg\TranslationBundle\Writer; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerAware; |
6
|
|
|
use Symfony\Component\Translation\MessageCatalogue; |
7
|
|
|
use Symfony\Component\Translation\Writer\TranslationWriter; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MessageCatalogWriter |
11
|
|
|
*/ |
12
|
|
|
class MessageCatalogueWriter extends ContainerAware |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var TranslationWriter |
16
|
|
|
*/ |
17
|
|
|
private $translationWriter; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param TranslationWriter $translationWriter |
21
|
|
|
*/ |
22
|
3 |
|
public function __construct(TranslationWriter $translationWriter) |
23
|
|
|
{ |
24
|
3 |
|
$this->translationWriter = $translationWriter; |
25
|
3 |
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param array $messageCatalogues |
29
|
|
|
* @param string $format |
30
|
|
|
* @param null|string $path |
31
|
|
|
*/ |
32
|
3 |
|
public function write(array $messageCatalogues, $format, $path = null) |
33
|
|
|
{ |
34
|
3 |
|
$this->translationWriter->addDumper($format, $this->getDumper($format)); |
35
|
|
|
|
36
|
|
|
/** @var MessageCatalogue $messageCatalogue */ |
37
|
3 |
|
foreach ($messageCatalogues as $messageCatalogue) { |
38
|
3 |
|
$this->translationWriter->writeTranslations($messageCatalogue, $format, array( |
39
|
3 |
|
'path' => $this->getTranslationPath($path)) |
40
|
3 |
|
); |
41
|
3 |
|
} |
42
|
3 |
|
} |
43
|
|
|
/** |
44
|
|
|
* Returns Symfony requested format dumper |
45
|
|
|
* |
46
|
|
|
* @param string $format |
47
|
|
|
* |
48
|
|
|
* @return \Symfony\Component\Translation\Dumper\DumperInterface |
49
|
|
|
* |
50
|
|
|
* @throws \InvalidArgumentException |
51
|
|
|
*/ |
52
|
3 |
View Code Duplication |
private function getDumper($format) |
|
|
|
|
53
|
|
|
{ |
54
|
3 |
|
$service = sprintf('translation.dumper.%s', $format); |
55
|
|
|
|
56
|
3 |
|
if (!$this->container->has($service)) { |
57
|
|
|
throw new \InvalidArgumentException(sprintf('Unable to find Symfony Translation dumper for format "%s"', $format)); |
58
|
|
|
} |
59
|
|
|
|
60
|
3 |
|
return $this->container->get($service); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns translation path |
65
|
|
|
* |
66
|
|
|
* @param string $outputPath |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
3 |
|
private function getTranslationPath($outputPath = null) |
71
|
|
|
{ |
72
|
3 |
|
if ($outputPath) { |
|
|
|
|
73
|
3 |
|
return $outputPath; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->container->get('kernel')->getRootDir() . '/Resources/translations'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.