aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/translation/Symfony/Component/Translation/Dumper
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/translation/Symfony/Component/Translation/Dumper')
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/CsvFileDumper.php63
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/DumperInterface.php31
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php65
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/IcuResFileDumper.php135
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/IniFileDumper.php45
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/MoFileDumper.php82
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/PhpFileDumper.php40
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/PoFileDumper.php55
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/QtFileDumper.php50
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/XliffFileDumper.php66
-rw-r--r--vendor/symfony/translation/Symfony/Component/Translation/Dumper/YamlFileDumper.php39
11 files changed, 671 insertions, 0 deletions
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/CsvFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/CsvFileDumper.php
new file mode 100644
index 00000000..0b411905
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/CsvFileDumper.php
@@ -0,0 +1,63 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * CsvFileDumper generates a csv formatted string representation of a message catalogue.
18 *
19 * @author Stealth35
20 */
21class CsvFileDumper extends FileDumper
22{
23 private $delimiter = ';';
24 private $enclosure = '"';
25
26 /**
27 * {@inheritDoc}
28 */
29 public function format(MessageCatalogue $messages, $domain = 'messages')
30 {
31 $handle = fopen('php://memory', 'rb+');
32
33 foreach ($messages->all($domain) as $source => $target) {
34 fputcsv($handle, array($source, $target), $this->delimiter, $this->enclosure);
35 }
36
37 rewind($handle);
38 $output = stream_get_contents($handle);
39 fclose($handle);
40
41 return $output;
42 }
43
44 /**
45 * Sets the delimiter and escape character for CSV.
46 *
47 * @param string $delimiter delimiter character
48 * @param string $enclosure enclosure character
49 */
50 public function setCsvControl($delimiter = ';', $enclosure = '"')
51 {
52 $this->delimiter = $delimiter;
53 $this->enclosure = $enclosure;
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 protected function getExtension()
60 {
61 return 'csv';
62 }
63}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/DumperInterface.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/DumperInterface.php
new file mode 100644
index 00000000..cebc65ed
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/DumperInterface.php
@@ -0,0 +1,31 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * DumperInterface is the interface implemented by all translation dumpers.
18 * There is no common option.
19 *
20 * @author Michel Salib <michelsalib@hotmail.com>
21 */
22interface DumperInterface
23{
24 /**
25 * Dumps the message catalogue.
26 *
27 * @param MessageCatalogue $messages The message catalogue
28 * @param array $options Options that are used by the dumper
29 */
30 public function dump(MessageCatalogue $messages, $options = array());
31}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
new file mode 100644
index 00000000..63c1e6c3
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/FileDumper.php
@@ -0,0 +1,65 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
18 * Performs backup of already existing files.
19 *
20 * Options:
21 * - path (mandatory): the directory where the files should be saved
22 *
23 * @author Michel Salib <michelsalib@hotmail.com>
24 */
25abstract class FileDumper implements DumperInterface
26{
27 /**
28 * {@inheritDoc}
29 */
30 public function dump(MessageCatalogue $messages, $options = array())
31 {
32 if (!array_key_exists('path', $options)) {
33 throw new \InvalidArgumentException('The file dumper need a path options.');
34 }
35
36 // save a file for each domain
37 foreach ($messages->getDomains() as $domain) {
38 $file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension();
39 // backup
40 $fullpath = $options['path'].'/'.$file;
41 if (file_exists($fullpath)) {
42 copy($fullpath, $fullpath.'~');
43 }
44 // save file
45 file_put_contents($fullpath, $this->format($messages, $domain));
46 }
47 }
48
49 /**
50 * Transforms a domain of a message catalogue to its string representation.
51 *
52 * @param MessageCatalogue $messages
53 * @param string $domain
54 *
55 * @return string representation
56 */
57 abstract protected function format(MessageCatalogue $messages, $domain);
58
59 /**
60 * Gets the file extension of the dumper.
61 *
62 * @return string file extension
63 */
64 abstract protected function getExtension();
65}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IcuResFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IcuResFileDumper.php
new file mode 100644
index 00000000..979153ac
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IcuResFileDumper.php
@@ -0,0 +1,135 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * IcuResDumper generates an ICU ResourceBundle formatted string representation of a message catalogue.
18 *
19 * @author Stealth35
20 */
21class IcuResFileDumper implements DumperInterface
22{
23 /**
24 * {@inheritDoc}
25 */
26 public function dump(MessageCatalogue $messages, $options = array())
27 {
28 if (!array_key_exists('path', $options)) {
29 throw new \InvalidArgumentException('The file dumper need a path options.');
30 }
31
32 // save a file for each domain
33 foreach ($messages->getDomains() as $domain) {
34 $file = $messages->getLocale().'.'.$this->getExtension();
35 $path = $options['path'].'/'.$domain.'/';
36
37 if (!file_exists($path)) {
38 mkdir($path);
39 }
40
41 // backup
42 if (file_exists($path.$file)) {
43 copy($path.$file, $path.$file.'~');
44 }
45
46 // save file
47 file_put_contents($path.$file, $this->format($messages, $domain));
48 }
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 public function format(MessageCatalogue $messages, $domain = 'messages')
55 {
56 $data = $indexes = $resources = '';
57
58 foreach ($messages->all($domain) as $source => $target) {
59 $indexes .= pack('v', strlen($data) + 28);
60 $data .= $source."\0";
61 }
62
63 $data .= $this->writePadding($data);
64
65 $keyTop = $this->getPosition($data);
66
67 foreach ($messages->all($domain) as $source => $target) {
68 $resources .= pack('V', $this->getPosition($data));
69
70 $data .= pack('V', strlen($target))
71 .mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8')
72 .$this->writePadding($data)
73 ;
74 }
75
76 $resOffset = $this->getPosition($data);
77
78 $data .= pack('v', count($messages))
79 .$indexes
80 .$this->writePadding($data)
81 .$resources
82 ;
83
84 $bundleTop = $this->getPosition($data);
85
86 $root = pack('V7',
87 $resOffset + (2 << 28), // Resource Offset + Resource Type
88 6, // Index length
89 $keyTop, // Index keys top
90 $bundleTop, // Index resources top
91 $bundleTop, // Index bundle top
92 count($messages), // Index max table length
93 0 // Index attributes
94 );
95
96 $header = pack('vC2v4C12@32',
97 32, // Header size
98 0xDA, 0x27, // Magic number 1 and 2
99 20, 0, 0, 2, // Rest of the header, ..., Size of a char
100 0x52, 0x65, 0x73, 0x42, // Data format identifier
101 1, 2, 0, 0, // Data version
102 1, 4, 0, 0 // Unicode version
103 );
104
105 $output = $header
106 .$root
107 .$data;
108
109 return $output;
110 }
111
112 private function writePadding($data)
113 {
114 $padding = strlen($data) % 4;
115
116 if ($padding) {
117 return str_repeat("\xAA", 4 - $padding);
118 }
119 }
120
121 private function getPosition($data)
122 {
123 $position = (strlen($data) + 28) / 4;
124
125 return $position;
126 }
127
128 /**
129 * {@inheritDoc}
130 */
131 protected function getExtension()
132 {
133 return 'res';
134 }
135}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IniFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IniFileDumper.php
new file mode 100644
index 00000000..173cf8c1
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/IniFileDumper.php
@@ -0,0 +1,45 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * IniFileDumper generates an ini formatted string representation of a message catalogue.
18 *
19 * @author Stealth35
20 */
21class IniFileDumper extends FileDumper
22{
23 /**
24 * {@inheritDoc}
25 */
26 public function format(MessageCatalogue $messages, $domain = 'messages')
27 {
28 $output = '';
29
30 foreach ($messages->all($domain) as $source => $target) {
31 $escapeTarget = str_replace('"', '\"', $target);
32 $output .= $source.'="'.$escapeTarget."\"\n";
33 }
34
35 return $output;
36 }
37
38 /**
39 * {@inheritDoc}
40 */
41 protected function getExtension()
42 {
43 return 'ini';
44 }
45}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/MoFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/MoFileDumper.php
new file mode 100644
index 00000000..a3a2a649
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/MoFileDumper.php
@@ -0,0 +1,82 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15use Symfony\Component\Translation\Loader\MoFileLoader;
16
17/**
18 * MoFileDumper generates a gettext formatted string representation of a message catalogue.
19 *
20 * @author Stealth35
21 */
22class MoFileDumper extends FileDumper
23{
24 /**
25 * {@inheritDoc}
26 */
27 public function format(MessageCatalogue $messages, $domain = 'messages')
28 {
29 $output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
30 $offsets = array();
31 $size = 0;
32
33 foreach ($messages->all($domain) as $source => $target) {
34 $offsets[] = array_map('strlen', array($sources, $source, $targets, $target));
35 $sources .= "\0".$source;
36 $targets .= "\0".$target;
37 ++$size;
38 }
39
40 $header = array(
41 'magicNumber' => MoFileLoader::MO_LITTLE_ENDIAN_MAGIC,
42 'formatRevision' => 0,
43 'count' => $size,
44 'offsetId' => MoFileLoader::MO_HEADER_SIZE,
45 'offsetTranslated' => MoFileLoader::MO_HEADER_SIZE + (8 * $size),
46 'sizeHashes' => 0,
47 'offsetHashes' => MoFileLoader::MO_HEADER_SIZE + (16 * $size),
48 );
49
50 $sourcesSize = strlen($sources);
51 $sourcesStart = $header['offsetHashes'] + 1;
52
53 foreach ($offsets as $offset) {
54 $sourceOffsets .= $this->writeLong($offset[1])
55 .$this->writeLong($offset[0] + $sourcesStart);
56 $targetOffsets .= $this->writeLong($offset[3])
57 .$this->writeLong($offset[2] + $sourcesStart + $sourcesSize);
58 }
59
60 $output = implode(array_map(array($this, 'writeLong'), $header))
61 .$sourceOffsets
62 .$targetOffsets
63 .$sources
64 .$targets
65 ;
66
67 return $output;
68 }
69
70 /**
71 * {@inheritDoc}
72 */
73 protected function getExtension()
74 {
75 return 'mo';
76 }
77
78 private function writeLong($str)
79 {
80 return pack('V*', $str);
81 }
82}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PhpFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PhpFileDumper.php
new file mode 100644
index 00000000..8de4a5b4
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/PhpFileDumper.php
@@ -0,0 +1,40 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * PhpFileDumper generates php files from a message catalogue.
18 *
19 * @author Michel Salib <michelsalib@hotmail.com>
20 */
21class PhpFileDumper extends FileDumper
22{
23 /**
24 * {@inheritDoc}
25 */
26 protected function format(MessageCatalogue $messages, $domain)
27 {
28 $output = "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
29
30 return $output;
31 }
32
33 /**
34 * {@inheritDoc}
35 */
36 protected function getExtension()
37 {
38 return 'php';
39 }
40}
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * PoFileDumper generates a gettext formatted string representation of a message catalogue.
18 *
19 * @author Stealth35
20 */
21class 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}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/QtFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/QtFileDumper.php
new file mode 100644
index 00000000..a1a84805
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/QtFileDumper.php
@@ -0,0 +1,50 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * QtFileDumper generates ts files from a message catalogue.
18 *
19 * @author Benjamin Eberlei <kontakt@beberlei.de>
20 */
21class QtFileDumper extends FileDumper
22{
23 /**
24 * {@inheritDoc}
25 */
26 public function format(MessageCatalogue $messages, $domain)
27 {
28 $dom = new \DOMDocument('1.0', 'utf-8');
29 $dom->formatOutput = true;
30 $ts = $dom->appendChild($dom->createElement('TS'));
31 $context = $ts->appendChild($dom->createElement('context'));
32 $context->appendChild($dom->createElement('name', $domain));
33
34 foreach ($messages->all($domain) as $source => $target) {
35 $message = $context->appendChild($dom->createElement('message'));
36 $message->appendChild($dom->createElement('source', $source));
37 $message->appendChild($dom->createElement('translation', $target));
38 }
39
40 return $dom->saveXML();
41 }
42
43 /**
44 * {@inheritDoc}
45 */
46 protected function getExtension()
47 {
48 return 'ts';
49 }
50}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/XliffFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/XliffFileDumper.php
new file mode 100644
index 00000000..0d258aad
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/XliffFileDumper.php
@@ -0,0 +1,66 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15
16/**
17 * XliffFileDumper generates xliff files from a message catalogue.
18 *
19 * @author Michel Salib <michelsalib@hotmail.com>
20 */
21class XliffFileDumper extends FileDumper
22{
23 /**
24 * {@inheritDoc}
25 */
26 protected function format(MessageCatalogue $messages, $domain)
27 {
28 $dom = new \DOMDocument('1.0', 'utf-8');
29 $dom->formatOutput = true;
30
31 $xliff = $dom->appendChild($dom->createElement('xliff'));
32 $xliff->setAttribute('version', '1.2');
33 $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
34
35 $xliffFile = $xliff->appendChild($dom->createElement('file'));
36 $xliffFile->setAttribute('source-language', $messages->getLocale());
37 $xliffFile->setAttribute('datatype', 'plaintext');
38 $xliffFile->setAttribute('original', 'file.ext');
39
40 $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
41 foreach ($messages->all($domain) as $source => $target) {
42 $translation = $dom->createElement('trans-unit');
43
44 $translation->setAttribute('id', md5($source));
45 $translation->setAttribute('resname', $source);
46
47 $s = $translation->appendChild($dom->createElement('source'));
48 $s->appendChild($dom->createTextNode($source));
49
50 $t = $translation->appendChild($dom->createElement('target'));
51 $t->appendChild($dom->createTextNode($target));
52
53 $xliffBody->appendChild($translation);
54 }
55
56 return $dom->saveXML();
57 }
58
59 /**
60 * {@inheritDoc}
61 */
62 protected function getExtension()
63 {
64 return 'xlf';
65 }
66}
diff --git a/vendor/symfony/translation/Symfony/Component/Translation/Dumper/YamlFileDumper.php b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/YamlFileDumper.php
new file mode 100644
index 00000000..d8072fb7
--- /dev/null
+++ b/vendor/symfony/translation/Symfony/Component/Translation/Dumper/YamlFileDumper.php
@@ -0,0 +1,39 @@
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
12namespace Symfony\Component\Translation\Dumper;
13
14use Symfony\Component\Translation\MessageCatalogue;
15use Symfony\Component\Yaml\Yaml;
16
17/**
18 * YamlFileDumper generates yaml files from a message catalogue.
19 *
20 * @author Michel Salib <michelsalib@hotmail.com>
21 */
22class YamlFileDumper extends FileDumper
23{
24 /**
25 * {@inheritDoc}
26 */
27 protected function format(MessageCatalogue $messages, $domain)
28 {
29 return Yaml::dump($messages->all($domain));
30 }
31
32 /**
33 * {@inheritDoc}
34 */
35 protected function getExtension()
36 {
37 return 'yml';
38 }
39}