4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Writer
;
14 use Symfony\Component\Translation\MessageCatalogue
;
15 use Symfony\Component\Translation\Dumper\DumperInterface
;
18 * TranslationWriter writes translation messages.
20 * @author Michel Salib <michelsalib@hotmail.com>
22 class TranslationWriter
25 * Dumpers used for export.
29 private $dumpers = array();
32 * Adds a dumper to the writer.
34 * @param string $format The format of the dumper
35 * @param DumperInterface $dumper The dumper
37 public function addDumper($format, DumperInterface
$dumper)
39 $this->dumpers
[$format] = $dumper;
43 * Obtains the list of supported formats.
47 public function getFormats()
49 return array_keys($this->dumpers
);
53 * Writes translation from the catalogue according to the selected format.
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
59 * @throws \InvalidArgumentException
61 public function writeTranslations(MessageCatalogue
$catalogue, $format, $options = array())
63 if (!isset($this->dumpers
[$format])) {
64 throw new \
InvalidArgumentException(sprintf('There is no dumper associated with format "%s".', $format));
67 // get the right dumper
68 $dumper = $this->dumpers
[$format];
71 $dumper->dump($catalogue, $options);