diff options
Diffstat (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php')
-rw-r--r-- | vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php new file mode 100644 index 00000000..d957ab91 --- /dev/null +++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php | |||
@@ -0,0 +1,55 @@ | |||
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 | } | ||