Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/translation/Dumper/PoFileDumper.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 formatCatalogue(MessageCatalogue $messages, $domain, array $options = array()) | |
27 { | |
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"; | |
34 | |
35 $newLine = false; | |
36 foreach ($messages->all($domain) as $source => $target) { | |
37 if ($newLine) { | |
38 $output .= "\n"; | |
39 } else { | |
40 $newLine = true; | |
41 } | |
42 $output .= sprintf('msgid "%s"'."\n", $this->escape($source)); | |
43 $output .= sprintf('msgstr "%s"', $this->escape($target)); | |
44 } | |
45 | |
46 return $output; | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 protected function getExtension() | |
53 { | |
54 return 'po'; | |
55 } | |
56 | |
57 private function escape($str) | |
58 { | |
59 return addcslashes($str, "\0..\37\42\134"); | |
60 } | |
61 } |