QtFileDumper.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 format(MessageCatalogue $messages, $domain)
  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. $message->appendChild($dom->createElement('source', $source));
  32. $message->appendChild($dom->createElement('translation', $target));
  33. }
  34. return $dom->saveXML();
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. protected function getExtension()
  40. {
  41. return 'ts';
  42. }
  43. }