Drupal investigation

QtFileDumper.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
  25. return $this->formatCatalogue($messages, $domain);
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  31. {
  32. $dom = new \DOMDocument('1.0', 'utf-8');
  33. $dom->formatOutput = true;
  34. $ts = $dom->appendChild($dom->createElement('TS'));
  35. $context = $ts->appendChild($dom->createElement('context'));
  36. $context->appendChild($dom->createElement('name', $domain));
  37. foreach ($messages->all($domain) as $source => $target) {
  38. $message = $context->appendChild($dom->createElement('message'));
  39. $message->appendChild($dom->createElement('source', $source));
  40. $message->appendChild($dom->createElement('translation', $target));
  41. }
  42. return $dom->saveXML();
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected function getExtension()
  48. {
  49. return 'ts';
  50. }
  51. }