composer package updates
[openemr.git] / vendor / symfony / translation / Dumper / MoFileDumper.php
blob00a33d253a9a9861ecd950bc487824a53750666b
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;
15 use Symfony\Component\Translation\Loader\MoFileLoader;
17 /**
18 * MoFileDumper generates a gettext formatted string representation of a message catalogue.
20 * @author Stealth35
22 class MoFileDumper extends FileDumper
24 /**
25 * {@inheritdoc}
27 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
29 $sources = $targets = $sourceOffsets = $targetOffsets = '';
30 $offsets = array();
31 $size = 0;
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;
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),
50 $sourcesSize = strlen($sources);
51 $sourcesStart = $header['offsetHashes'] + 1;
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);
60 $output = implode(array_map(array($this, 'writeLong'), $header))
61 .$sourceOffsets
62 .$targetOffsets
63 .$sources
64 .$targets
67 return $output;
70 /**
71 * {@inheritdoc}
73 protected function getExtension()
75 return 'mo';
78 private function writeLong($str)
80 return pack('V*', $str);