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
;
18 * MoFileDumper generates a gettext formatted string representation of a message catalogue.
22 class MoFileDumper
extends FileDumper
27 public function format(MessageCatalogue
$messages, $domain = 'messages')
29 $output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
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;
41 'magicNumber' => MoFileLoader
::MO_LITTLE_ENDIAN_MAGIC
,
42 'formatRevision' => 0,
44 'offsetId' => MoFileLoader
::MO_HEADER_SIZE
,
45 'offsetTranslated' => MoFileLoader
::MO_HEADER_SIZE +
(8 * $size),
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))
73 protected function getExtension()
78 private function writeLong($str)
80 return pack('V*', $str);