CsvFileDumper.php
2 months ago
DumperInterface.php
2 months ago
FileDumper.php
2 months ago
IcuResFileDumper.php
2 months ago
IniFileDumper.php
2 months ago
JsonFileDumper.php
2 months ago
MoFileDumper.php
2 months ago
PhpFileDumper.php
2 months ago
PoFileDumper.php
2 months ago
QtFileDumper.php
2 months ago
XliffFileDumper.php
2 months ago
YamlFileDumper.php
2 months ago
MoFileDumper.php
58 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 ProfilePressVendor\Symfony\Component\Translation\Dumper; |
| 12 | |
| 13 | use ProfilePressVendor\Symfony\Component\Translation\Loader\MoFileLoader; |
| 14 | use ProfilePressVendor\Symfony\Component\Translation\MessageCatalogue; |
| 15 | /** |
| 16 | * MoFileDumper generates a gettext formatted string representation of a message catalogue. |
| 17 | * |
| 18 | * @author Stealth35 |
| 19 | */ |
| 20 | class MoFileDumper extends FileDumper |
| 21 | { |
| 22 | /** |
| 23 | * {@inheritdoc} |
| 24 | */ |
| 25 | public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []) |
| 26 | { |
| 27 | $sources = $targets = $sourceOffsets = $targetOffsets = ''; |
| 28 | $offsets = []; |
| 29 | $size = 0; |
| 30 | foreach ($messages->all($domain) as $source => $target) { |
| 31 | $offsets[] = array_map('strlen', [$sources, $source, $targets, $target]); |
| 32 | $sources .= "\x00" . $source; |
| 33 | $targets .= "\x00" . $target; |
| 34 | ++$size; |
| 35 | } |
| 36 | $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]; |
| 37 | $sourcesSize = \strlen($sources); |
| 38 | $sourcesStart = $header['offsetHashes'] + 1; |
| 39 | foreach ($offsets as $offset) { |
| 40 | $sourceOffsets .= $this->writeLong($offset[1]) . $this->writeLong($offset[0] + $sourcesStart); |
| 41 | $targetOffsets .= $this->writeLong($offset[3]) . $this->writeLong($offset[2] + $sourcesStart + $sourcesSize); |
| 42 | } |
| 43 | $output = implode('', array_map([$this, 'writeLong'], $header)) . $sourceOffsets . $targetOffsets . $sources . $targets; |
| 44 | return $output; |
| 45 | } |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | protected function getExtension() |
| 50 | { |
| 51 | return 'mo'; |
| 52 | } |
| 53 | private function writeLong($str): string |
| 54 | { |
| 55 | return pack('V*', $str); |
| 56 | } |
| 57 | } |
| 58 |