aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php')
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php b/vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php
new file mode 100644
index 00000000..9d70c12f
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php
@@ -0,0 +1,73 @@
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Translation\Writer;
13
14use Symfony\Component\Translation\MessageCatalogue;
15use Symfony\Component\Translation\Dumper\DumperInterface;
16
17/**
18 * TranslationWriter writes translation messages.
19 *
20 * @author Michel Salib <michelsalib@hotmail.com>
21 */
22class TranslationWriter
23{
24 /**
25 * Dumpers used for export.
26 *
27 * @var array
28 */
29 private $dumpers = array();
30
31 /**
32 * Adds a dumper to the writer.
33 *
34 * @param string $format The format of the dumper
35 * @param DumperInterface $dumper The dumper
36 */
37 public function addDumper($format, DumperInterface $dumper)
38 {
39 $this->dumpers[$format] = $dumper;
40 }
41
42 /**
43 * Obtains the list of supported formats.
44 *
45 * @return array
46 */
47 public function getFormats()
48 {
49 return array_keys($this->dumpers);
50 }
51
52 /**
53 * Writes translation from the catalogue according to the selected format.
54 *
55 * @param MessageCatalogue $catalogue The message catalogue to dump
56 * @param string $format The format to use to dump the messages
57 * @param array $options Options that are passed to the dumper
58 *
59 * @throws \InvalidArgumentException
60 */
61 public function writeTranslations(MessageCatalogue $catalogue, $format, $options = array())
62 {
63 if (!isset($this->dumpers[$format])) {
64 throw new \InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
65 }
66
67 // get the right dumper
68 $dumper = $this->dumpers[$format];
69
70 // save
71 $dumper->dump($catalogue, $options);
72 }
73}