Nav apraksta

QtFileDumper.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Dumper;
  11. use Symfony\Component\Translation\MessageCatalogue;
  12. /**
  13. * QtFileDumper generates ts files from a message catalogue.
  14. *
  15. * @author Benjamin Eberlei <kontakt@beberlei.de>
  16. */
  17. class QtFileDumper extends FileDumper
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
  23. {
  24. $dom = new \DOMDocument('1.0', 'utf-8');
  25. $dom->formatOutput = true;
  26. $ts = $dom->appendChild($dom->createElement('TS'));
  27. $context = $ts->appendChild($dom->createElement('context'));
  28. $context->appendChild($dom->createElement('name', $domain));
  29. foreach ($messages->all($domain) as $source => $target) {
  30. $message = $context->appendChild($dom->createElement('message'));
  31. $metadata = $messages->getMetadata($source, $domain);
  32. if (isset($metadata['sources'])) {
  33. foreach ((array) $metadata['sources'] as $location) {
  34. $loc = explode(':', $location, 2);
  35. $location = $message->appendChild($dom->createElement('location'));
  36. $location->setAttribute('filename', $loc[0]);
  37. if (isset($loc[1])) {
  38. $location->setAttribute('line', $loc[1]);
  39. }
  40. }
  41. }
  42. $message->appendChild($dom->createElement('source', $source));
  43. $message->appendChild($dom->createElement('translation', $target));
  44. }
  45. return $dom->saveXML();
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function getExtension()
  51. {
  52. return 'ts';
  53. }
  54. }