YamlFileDumper.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. use Symfony\Component\Translation\Util\ArrayConverter;
  13. use Symfony\Component\Yaml\Yaml;
  14. /**
  15. * YamlFileDumper generates yaml files from a message catalogue.
  16. *
  17. * @author Michel Salib <michelsalib@hotmail.com>
  18. */
  19. class YamlFileDumper extends FileDumper
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  25. {
  26. if (!class_exists('Symfony\Component\Yaml\Yaml')) {
  27. throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
  28. }
  29. $data = $messages->all($domain);
  30. if (isset($options['as_tree']) && $options['as_tree']) {
  31. $data = ArrayConverter::expandToTree($data);
  32. }
  33. if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
  34. return Yaml::dump($data, $inline);
  35. }
  36. return Yaml::dump($data);
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function getExtension()
  42. {
  43. return 'yml';
  44. }
  45. }