composer package updates
[openemr.git] / vendor / symfony / translation / Dumper / IcuResFileDumper.php
blob42f159501a859e222ead20385275fade5c865a66
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;
16 /**
17 * IcuResDumper generates an ICU ResourceBundle formatted string representation of a message catalogue.
19 * @author Stealth35
21 class IcuResFileDumper extends FileDumper
23 /**
24 * {@inheritdoc}
26 protected $relativePathTemplate = '%domain%/%locale%.%extension%';
28 /**
29 * {@inheritdoc}
31 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
33 $data = $indexes = $resources = '';
35 foreach ($messages->all($domain) as $source => $target) {
36 $indexes .= pack('v', strlen($data) + 28);
37 $data .= $source."\0";
40 $data .= $this->writePadding($data);
42 $keyTop = $this->getPosition($data);
44 foreach ($messages->all($domain) as $source => $target) {
45 $resources .= pack('V', $this->getPosition($data));
47 $data .= pack('V', strlen($target))
48 .mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8')
49 .$this->writePadding($data)
53 $resOffset = $this->getPosition($data);
55 $data .= pack('v', count($messages->all($domain)))
56 .$indexes
57 .$this->writePadding($data)
58 .$resources
61 $bundleTop = $this->getPosition($data);
63 $root = pack('V7',
64 $resOffset + (2 << 28), // Resource Offset + Resource Type
65 6, // Index length
66 $keyTop, // Index keys top
67 $bundleTop, // Index resources top
68 $bundleTop, // Index bundle top
69 count($messages->all($domain)), // Index max table length
70 0 // Index attributes
73 $header = pack('vC2v4C12@32',
74 32, // Header size
75 0xDA, 0x27, // Magic number 1 and 2
76 20, 0, 0, 2, // Rest of the header, ..., Size of a char
77 0x52, 0x65, 0x73, 0x42, // Data format identifier
78 1, 2, 0, 0, // Data version
79 1, 4, 0, 0 // Unicode version
82 return $header.$root.$data;
85 private function writePadding($data)
87 $padding = strlen($data) % 4;
89 if ($padding) {
90 return str_repeat("\xAA", 4 - $padding);
94 private function getPosition($data)
96 return (strlen($data) + 28) / 4;
99 /**
100 * {@inheritdoc}
102 protected function getExtension()
104 return 'res';