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;
17 * IcuResDumper generates an ICU ResourceBundle formatted string representation of a message catalogue.
21 class IcuResFileDumper extends FileDumper
26 protected $relativePathTemplate = '%domain%/%locale%.%extension%';
31 public function format(MessageCatalogue $messages, $domain = 'messages')
33 @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);
35 return $this->formatCatalogue($messages, $domain);
41 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
43 $data = $indexes = $resources = '';
45 foreach ($messages->all($domain) as $source => $target) {
46 $indexes .= pack('v', strlen($data) + 28);
47 $data .= $source."\0";
50 $data .= $this->writePadding($data);
52 $keyTop = $this->getPosition($data);
54 foreach ($messages->all($domain) as $source => $target) {
55 $resources .= pack('V', $this->getPosition($data));
57 $data .= pack('V', strlen($target))
58 .mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8')
59 .$this->writePadding($data)
63 $resOffset = $this->getPosition($data);
65 $data .= pack('v', count($messages))
67 .$this->writePadding($data)
71 $bundleTop = $this->getPosition($data);
74 $resOffset + (2 << 28), // Resource Offset + Resource Type
76 $keyTop, // Index keys top
77 $bundleTop, // Index resources top
78 $bundleTop, // Index bundle top
79 count($messages), // Index max table length
83 $header = pack('vC2v4C12@32',
85 0xDA, 0x27, // Magic number 1 and 2
86 20, 0, 0, 2, // Rest of the header, ..., Size of a char
87 0x52, 0x65, 0x73, 0x42, // Data format identifier
88 1, 2, 0, 0, // Data version
89 1, 4, 0, 0 // Unicode version
92 return $header.$root.$data;
95 private function writePadding($data)
97 $padding = strlen($data) % 4;
100 return str_repeat("\xAA", 4 - $padding);
104 private function getPosition($data)
106 return (strlen($data) + 28) / 4;
112 protected function getExtension()