菜谱项目

QtFileDumper.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 = array())
  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. }