]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/translation/Symfony/Component/Translation/Writer/TranslationWriter.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / translation / Symfony / Component / Translation / Writer / TranslationWriter.php
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
12 namespace Symfony\Component\Translation\Writer;
13
14 use Symfony\Component\Translation\MessageCatalogue;
15 use Symfony\Component\Translation\Dumper\DumperInterface;
16
17 /**
18 * TranslationWriter writes translation messages.
19 *
20 * @author Michel Salib <michelsalib@hotmail.com>
21 */
22 class 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 }