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\Dumper
;
14 use Symfony\Component\Translation\MessageCatalogue
;
17 * XliffFileDumper generates xliff files from a message catalogue.
19 * @author Michel Salib <michelsalib@hotmail.com>
21 class XliffFileDumper
extends FileDumper
26 protected function format(MessageCatalogue
$messages, $domain)
28 $dom = new \
DOMDocument('1.0', 'utf-8');
29 $dom->formatOutput
= true;
31 $xliff = $dom->appendChild($dom->createElement('xliff'));
32 $xliff->setAttribute('version', '1.2');
33 $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
35 $xliffFile = $xliff->appendChild($dom->createElement('file'));
36 $xliffFile->setAttribute('source-language', $messages->getLocale());
37 $xliffFile->setAttribute('datatype', 'plaintext');
38 $xliffFile->setAttribute('original', 'file.ext');
40 $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
41 foreach ($messages->all($domain) as $source => $target) {
42 $translation = $dom->createElement('trans-unit');
44 $translation->setAttribute('id', md5($source));
45 $translation->setAttribute('resname', $source);
47 $s = $translation->appendChild($dom->createElement('source'));
48 $s->appendChild($dom->createTextNode($source));
50 $t = $translation->appendChild($dom->createElement('target'));
51 $t->appendChild($dom->createTextNode($target));
53 $xliffBody->appendChild($translation);
56 return $dom->saveXML();
62 protected function getExtension()