]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/translation/Symfony/Component/Translation/Dumper/XliffFileDumper.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / translation / Symfony / Component / Translation / Dumper / XliffFileDumper.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\Dumper;
13
14 use Symfony\Component\Translation\MessageCatalogue;
15
16 /**
17 * XliffFileDumper generates xliff files from a message catalogue.
18 *
19 * @author Michel Salib <michelsalib@hotmail.com>
20 */
21 class XliffFileDumper extends FileDumper
22 {
23 /**
24 * {@inheritDoc}
25 */
26 protected function format(MessageCatalogue $messages, $domain)
27 {
28 $dom = new \DOMDocument('1.0', 'utf-8');
29 $dom->formatOutput = true;
30
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');
34
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');
39
40 $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
41 foreach ($messages->all($domain) as $source => $target) {
42 $translation = $dom->createElement('trans-unit');
43
44 $translation->setAttribute('id', md5($source));
45 $translation->setAttribute('resname', $source);
46
47 $s = $translation->appendChild($dom->createElement('source'));
48 $s->appendChild($dom->createTextNode($source));
49
50 $t = $translation->appendChild($dom->createElement('target'));
51 $t->appendChild($dom->createTextNode($target));
52
53 $xliffBody->appendChild($translation);
54 }
55
56 return $dom->saveXML();
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 protected function getExtension()
63 {
64 return 'xlf';
65 }
66 }