Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Dumper/QtFileDumper.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 * QtFileDumper generates ts files from a message catalogue.
18 *
19 * @author Benjamin Eberlei <[email protected]>
20 */
21 class QtFileDumper extends FileDumper
22 {
23 public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string
24 {
25 $dom = new \DOMDocument('1.0', 'utf-8');
26 $dom->formatOutput = true;
27 $ts = $dom->appendChild($dom->createElement('TS'));
28 $context = $ts->appendChild($dom->createElement('context'));
29 $context->appendChild($dom->createElement('name', $domain));
30
31 foreach ($messages->all($domain) as $source => $target) {
32 $message = $context->appendChild($dom->createElement('message'));
33 $metadata = $messages->getMetadata($source, $domain);
34 if (isset($metadata['sources'])) {
35 foreach ((array) $metadata['sources'] as $location) {
36 $loc = explode(':', $location, 2);
37 $location = $message->appendChild($dom->createElement('location'));
38 $location->setAttribute('filename', $loc[0]);
39 if (isset($loc[1])) {
40 $location->setAttribute('line', $loc[1]);
41 }
42 }
43 }
44 $message->appendChild($dom->createElement('source', $source));
45 $message->appendChild($dom->createElement('translation', $target));
46 }
47
48 return $dom->saveXML();
49 }
50
51 protected function getExtension(): string
52 {
53 return 'ts';
54 }
55 }