| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Dumper; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\MessageCatalogue; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
} |