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 @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
31 return $this->formatCatalogue($messages, $domain);
37 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
39 $sources = $targets = $sourceOffsets = $targetOffsets = '';
43 foreach ($messages->all($domain) as $source => $target) {
44 $offsets[] = array_map('strlen', array($sources, $source, $targets, $target));
45 $sources .= "\0".$source;
46 $targets .= "\0".$target;
51 'magicNumber' => MoFileLoader::MO_LITTLE_ENDIAN_MAGIC,
52 'formatRevision' => 0,
54 'offsetId' => MoFileLoader::MO_HEADER_SIZE,
55 'offsetTranslated' => MoFileLoader::MO_HEADER_SIZE + (8 * $size),
57 'offsetHashes' => MoFileLoader::MO_HEADER_SIZE + (16 * $size),
60 $sourcesSize = strlen($sources);
61 $sourcesStart = $header['offsetHashes'] + 1;
63 foreach ($offsets as $offset) {
64 $sourceOffsets .= $this->writeLong($offset[1])
65 .$this->writeLong($offset[0] + $sourcesStart);
66 $targetOffsets .= $this->writeLong($offset[3])
67 .$this->writeLong($offset[2] + $sourcesStart + $sourcesSize);
70 $output = implode(array_map(array($this, 'writeLong'), $header))
83 protected function getExtension()
88 private function writeLong($str)
90 return pack('V*', $str);