CsvFileDumper.php
1 month ago
DumperInterface.php
2 years ago
FileDumper.php
1 month ago
IcuResFileDumper.php
1 month ago
IniFileDumper.php
1 month ago
JsonFileDumper.php
1 month ago
MoFileDumper.php
1 month ago
PhpFileDumper.php
1 month ago
PoFileDumper.php
1 month ago
QtFileDumper.php
1 month ago
XliffFileDumper.php
1 month ago
YamlFileDumper.php
1 month ago
MoFileDumper.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace IAWPSCOPED\Symfony\Component\Translation\Dumper; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\Loader\MoFileLoader; |
| 14 | use IAWPSCOPED\Symfony\Component\Translation\MessageCatalogue; |
| 15 | /** |
| 16 | * MoFileDumper generates a gettext formatted string representation of a message catalogue. |
| 17 | * |
| 18 | * @author Stealth35 |
| 19 | * @internal |
| 20 | */ |
| 21 | class MoFileDumper extends FileDumper |
| 22 | { |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []) : string |
| 27 | { |
| 28 | $sources = $targets = $sourceOffsets = $targetOffsets = ''; |
| 29 | $offsets = []; |
| 30 | $size = 0; |
| 31 | foreach ($messages->all($domain) as $source => $target) { |
| 32 | $offsets[] = \array_map('strlen', [$sources, $source, $targets, $target]); |
| 33 | $sources .= "\x00" . $source; |
| 34 | $targets .= "\x00" . $target; |
| 35 | ++$size; |
| 36 | } |
| 37 | $header = ['magicNumber' => MoFileLoader::MO_LITTLE_ENDIAN_MAGIC, 'formatRevision' => 0, 'count' => $size, 'offsetId' => MoFileLoader::MO_HEADER_SIZE, 'offsetTranslated' => MoFileLoader::MO_HEADER_SIZE + 8 * $size, 'sizeHashes' => 0, 'offsetHashes' => MoFileLoader::MO_HEADER_SIZE + 16 * $size]; |
| 38 | $sourcesSize = \strlen($sources); |
| 39 | $sourcesStart = $header['offsetHashes'] + 1; |
| 40 | foreach ($offsets as $offset) { |
| 41 | $sourceOffsets .= $this->writeLong($offset[1]) . $this->writeLong($offset[0] + $sourcesStart); |
| 42 | $targetOffsets .= $this->writeLong($offset[3]) . $this->writeLong($offset[2] + $sourcesStart + $sourcesSize); |
| 43 | } |
| 44 | $output = \implode('', \array_map([$this, 'writeLong'], $header)) . $sourceOffsets . $targetOffsets . $sources . $targets; |
| 45 | return $output; |
| 46 | } |
| 47 | /** |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | protected function getExtension() : string |
| 51 | { |
| 52 | return 'mo'; |
| 53 | } |
| 54 | private function writeLong(mixed $str) : string |
| 55 | { |
| 56 | return \pack('V*', $str); |
| 57 | } |
| 58 | } |
| 59 |