4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Dumper;
14 use Symfony\Component\Translation\MessageCatalogue;
17 * PoFileDumper generates a gettext formatted string representation of a message catalogue.
21 class PoFileDumper extends FileDumper
26 public function format(MessageCatalogue $messages, $domain = 'messages')
28 @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);
30 return $this->formatCatalogue($messages, $domain);
36 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
38 $output = 'msgid ""'."\n";
39 $output .= 'msgstr ""'."\n";
40 $output .= '"Content-Type: text/plain; charset=UTF-8\n"'."\n";
41 $output .= '"Content-Transfer-Encoding: 8bit\n"'."\n";
42 $output .= '"Language: '.$messages->getLocale().'\n"'."\n";
46 foreach ($messages->all($domain) as $source => $target) {
52 $output .= sprintf('msgid "%s"'."\n", $this->escape($source));
53 $output .= sprintf('msgstr "%s"', $this->escape($target));
62 protected function getExtension()
67 private function escape($str)
69 return addcslashes($str, "\0..\37\42\134");