]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / translation / Symfony / Component / Translation / Dumper / PoFileDumper.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Translation\Dumper;
13
14 use Symfony\Component\Translation\MessageCatalogue;
15
16 /**
17 * PoFileDumper generates a gettext formatted string representation of a message catalogue.
18 *
19 * @author Stealth35
20 */
21 class PoFileDumper extends FileDumper
22 {
23 /**
24 * {@inheritDoc}
25 */
26 public function format(MessageCatalogue $messages, $domain = 'messages')
27 {
28 $output = '';
29 $newLine = false;
30 foreach ($messages->all($domain) as $source => $target) {
31 if ($newLine) {
32 $output .= "\n";
33 } else {
34 $newLine = true;
35 }
36 $output .= sprintf('msgid "%s"'."\n", $this->escape($source));
37 $output .= sprintf('msgstr "%s"', $this->escape($target));
38 }
39
40 return $output;
41 }
42
43 /**
44 * {@inheritDoc}
45 */
46 protected function getExtension()
47 {
48 return 'po';
49 }
50
51 private function escape($str)
52 {
53 return addcslashes($str, "\0..\37\42\134");
54 }
55 }