/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/I18n/Parser
NameSizeModeActions
MoFileParser.php52510644editdlrm
PoFileParser.php71190644editdlrm
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/I18n/Parser/PoFileParser.php (7119B)
[], 'translated' => null, ]; $messages = []; $item = $defaults; $stage = []; while ($line = fgets($stream)) { $line = trim($line); if ($line === '') { // Whitespace indicated current item is done $this->_addMessage($messages, $item); $item = $defaults; $stage = []; } elseif (substr($line, 0, 7) === 'msgid "') { // We start a new msg so save previous $this->_addMessage($messages, $item); /** @psalm-suppress InvalidArrayOffset */ $item['ids']['singular'] = substr($line, 7, -1); $stage = ['ids', 'singular']; } elseif (substr($line, 0, 8) === 'msgstr "') { $item['translated'] = substr($line, 8, -1); $stage = ['translated']; } elseif (substr($line, 0, 9) === 'msgctxt "') { $item['context'] = substr($line, 9, -1); $stage = ['context']; } elseif ($line[0] === '"') { switch (count($stage)) { case 2: /** * @psalm-suppress PossiblyUndefinedArrayOffset * @psalm-suppress InvalidArrayOffset * @psalm-suppress PossiblyNullArrayAccess */ $item[$stage[0]][$stage[1]] .= substr($line, 1, -1); break; case 1: /** * @psalm-suppress PossiblyUndefinedArrayOffset * @psalm-suppress PossiblyInvalidOperand * @psalm-suppress PossiblyNullOperand */ $item[$stage[0]] .= substr($line, 1, -1); break; } } elseif (substr($line, 0, 14) === 'msgid_plural "') { /** @psalm-suppress InvalidArrayOffset */ $item['ids']['plural'] = substr($line, 14, -1); $stage = ['ids', 'plural']; } elseif (substr($line, 0, 7) === 'msgstr[') { /** @var int $size */ $size = strpos($line, ']'); $row = (int)substr($line, 7, 1); $item['translated'][$row] = substr($line, $size + 3, -1); $stage = ['translated', $row]; } } // save last item $this->_addMessage($messages, $item); fclose($stream); return $messages; } /** * Saves a translation item to the messages. * * @param array $messages The messages array being collected from the file * @param array $item The current item being inspected * @return void */ protected function _addMessage(array &$messages, array $item): void { if (empty($item['ids']['singular']) && empty($item['ids']['plural'])) { return; } $singular = stripcslashes($item['ids']['singular']); $context = $item['context'] ?? null; $translation = $item['translated']; if (is_array($translation)) { $translation = $translation[0]; } $translation = stripcslashes((string)$translation); if ($context !== null && !isset($messages[$singular]['_context'][$context])) { $messages[$singular]['_context'][$context] = $translation; } elseif (!isset($messages[$singular]['_context'][''])) { $messages[$singular]['_context'][''] = $translation; } if (isset($item['ids']['plural'])) { $plurals = $item['translated']; // PO are by definition indexed so sort by index. ksort($plurals); // Make sure every index is filled. end($plurals); $count = (int)key($plurals); // Fill missing spots with an empty string. $empties = array_fill(0, $count + 1, ''); $plurals += $empties; ksort($plurals); $plurals = array_map('stripcslashes', $plurals); $key = stripcslashes($item['ids']['plural']); if ($context !== null) { $messages[Translator::PLURAL_PREFIX . $key]['_context'][$context] = $plurals; } else { $messages[Translator::PLURAL_PREFIX . $key]['_context'][''] = $plurals; } } } }