composer package updates
[openemr.git] / vendor / symfony / translation / Dumper / PoFileDumper.php
blobed4418b1489eab83e9146e5fc617e00f413775a7
1 <?php
3 /*
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;
16 /**
17 * PoFileDumper generates a gettext formatted string representation of a message catalogue.
19 * @author Stealth35
21 class PoFileDumper extends FileDumper
23 /**
24 * {@inheritdoc}
26 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
28 $output = 'msgid ""'."\n";
29 $output .= 'msgstr ""'."\n";
30 $output .= '"Content-Type: text/plain; charset=UTF-8\n"'."\n";
31 $output .= '"Content-Transfer-Encoding: 8bit\n"'."\n";
32 $output .= '"Language: '.$messages->getLocale().'\n"'."\n";
33 $output .= "\n";
35 $newLine = false;
36 foreach ($messages->all($domain) as $source => $target) {
37 if ($newLine) {
38 $output .= "\n";
39 } else {
40 $newLine = true;
42 $output .= sprintf('msgid "%s"'."\n", $this->escape($source));
43 $output .= sprintf('msgstr "%s"', $this->escape($target));
46 return $output;
49 /**
50 * {@inheritdoc}
52 protected function getExtension()
54 return 'po';
57 private function escape($str)
59 return addcslashes($str, "\0..\37\42\134");