Drupal investigation

PoFileDumper.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. * PoFileDumper generates a gettext formatted string representation of a message catalogue.
  14. *
  15. * @author Stealth35
  16. */
  17. class PoFileDumper extends FileDumper
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function format(MessageCatalogue $messages, $domain = 'messages')
  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. $output = 'msgid ""'."\n";
  33. $output .= 'msgstr ""'."\n";
  34. $output .= '"Content-Type: text/plain; charset=UTF-8\n"'."\n";
  35. $output .= '"Content-Transfer-Encoding: 8bit\n"'."\n";
  36. $output .= '"Language: '.$messages->getLocale().'\n"'."\n";
  37. $output .= "\n";
  38. $newLine = false;
  39. foreach ($messages->all($domain) as $source => $target) {
  40. if ($newLine) {
  41. $output .= "\n";
  42. } else {
  43. $newLine = true;
  44. }
  45. $output .= sprintf('msgid "%s"'."\n", $this->escape($source));
  46. $output .= sprintf('msgstr "%s"', $this->escape($target));
  47. }
  48. return $output;
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. protected function getExtension()
  54. {
  55. return 'po';
  56. }
  57. private function escape($str)
  58. {
  59. return addcslashes($str, "\0..\37\42\134");
  60. }
  61. }