Transforms an array of nested translation messages into a "flat" (not nested) array.

@param array $nestedMessages
@param string $keyPrefix
@return array Flattened translations array.
321715
protected function flattenTranslations(array $nestedMessages, $keyPrefix='')
    {
        $flattened = [];

        foreach ($nestedMessages as $key => $message) {
            if (is_array($message)) {
                $flattenedMessages = $this->flattenTranslations($message, $keyPrefix . $key . '.');
                $flattened = array_merge($flattened, $flattenedMessages);
            } else {
                $flattened[$keyPrefix.$key] = $message;
            }
        }

        return $flattened;
    }
981770
public function buildMessages(
        string $fieldName,
        ValidationResult $validationResult,
        array $messages = [],
        array $options = []
    ): array {
        if ($validationResult instanceof ValidationResultFields) {
            $options[Field::KEY_FIELD_NAME] = $fieldName;
            $subMessages = $this->buildMessagesValidationFields(
                $validationResult->getFieldResults(),
                [],
                $options
            );

            $messages = $this->flattenSubMessages(
                $fieldName,
                $subMessages,
                $messages
            );

            return $messages;
        }

        $options[Field::KEY_FIELD_NAME] = $fieldName;
        $messages[$fieldName] = $this->getMessagesValidationResult->__invoke(
            $validationResult,
            $options
        );

        return $messages;
    }
692908
public function addSubjectPrefix($subjectPrefix, $roles)
    {
        if (!is_array($roles)) {
            $roles = array($roles);
        }
        if (is_array($subjectPrefix)) {
            foreach ($subjectPrefix as $oneSubjectPrefix) {
                $this->addSubjectPrefix($oneSubjectPrefix, $roles);
            }
        } else {
            if (isset($this->subjectPrefixes[$subjectPrefix])) {
                $this->subjectPrefixes[$subjectPrefix] = array_values(array_unique(array_merge(
                            $this->subjectPrefixes[$subjectPrefix], $roles)));
            } else {
                $this->subjectPrefixes[$subjectPrefix] = $roles;
            }
        }
        return $this;
    }
411825
public function transImplode(array $keys, string $glue = ' ')
    {
        $text = [];
        foreach ($keys as $key) {
            $text[] = $this->trans($key);
        }

        return implode($glue, $text);
    }
588529
protected function transformMessage(ParsedMessage $parsedMessage)
    {
        $message = new \Swift_Message();

        if ($from = $parsedMessage->getFrom()) {
            $message->setFrom($from);
        }

        // handle to with defaults
        if ($to = $parsedMessage->getTo()) {
            $message->setTo($to);
        }

        // handle cc with defaults
        if ($cc = $parsedMessage->getCc()) {
            $message->setCc($cc);
        }

        // handle bcc with defaults
        if ($bcc = $parsedMessage->getBcc()) {
            $message->setBcc($bcc);
        }

        // handle reply to with defaults
        if ($replyTo = $parsedMessage->getReplyTo()) {
            $message->setReplyTo($replyTo);
        }

        // handle subject with default
        if ($subject = $parsedMessage->getSubject()) {
            $message->setSubject($subject);
        }

        // handle body, no default values here
        $message->setBody($parsedMessage->getMessageText());
        if ($parsedMessage->getMessageHtml()) {
            $message->addPart($parsedMessage->getMessageHtml(), 'text/html');
        }

        return $message;
    }
28598
public function prepareTranslatedMessage(array $message = [])
    {
        $translatedMessage = \App\Registry::$translate->_($message['message']);
        array_unshift($message['vars'], $translatedMessage);
        return call_user_func_array('sprintf', $message['vars']);
    }
422565
protected function mapMessagesToElementCollection(array $messages, ElementCollection $children)
    {
        $children->forAll(function (ElementInterface $element) use ($messages) {
            $this->mapMessagesToElement($messages, $element);
        });
    }
950561
private function prepareMessages()
    {
        $prepared = [];

        foreach ($this->messages as $key => $msg) {
            $prepared[(string)$key] = $msg;
        }

        $this->messages = $prepared;
    }
1232400
protected function makeMessages($rawMessages)
    {
        $incomingMessages = [];
        foreach ($rawMessages as $rawMessage) {
            $incomingMessages[] = $this->processReceive($rawMessage);
        }

        return $incomingMessages;
    }
462731
public function translate($message, array $params = array())
    {
        // Update the current message with the domain translation, if we have one.
        if (isset($this->messages[$message]) && ! empty($this->messages[$message])) {
            $message = $this->messages[$message];
        }

        if (empty($params)) {
            return $message;
        }

        $formatter = new MessageFormatter();

        return $formatter->format($message, $params, $this->locale);
    }
836777
protected function installKeysAndTranslations(array $translations)
    {
        $results = [];
        foreach ($translations as $keyName => $data) {
            $results[$keyName]['created'] = false;
            if (!$this->glossaryFacade->hasKey($keyName)) {
                $this->glossaryFacade->createKey($keyName);
                $results[$keyName]['created'] = true;
            }

            foreach ($data['translations'] as $localeName => $text) {
                $results[$keyName]['translation'][$localeName] = $this->addTranslation($localeName, $keyName, $text);
            }
        }

        return $results;
    }
53029
public function getMessages()
    {
        $messages = $this->fromPrevious;

        foreach ($this->forNow as $key => $values) {
            if (!isset($messages[$key])) {
                $messages[$key] = [];
            }

            foreach ($values as $value) {
                array_push($messages[$key], $value);
            }
        }

        return $messages;
    }
478072
public function setMessageGroups(array $messageGroups)
    {
        $this->messageGroups = $messageGroups;

        // Set the joined message groups as well
        foreach ($this->messageGroups as $header => $keywords) {
            $this->messageGroupsJoined[$header] = join('|', $keywords);
        }

        return $this;
    }
4121
protected function parseNestedKeyPairHeader($nestedPairs)
    {
        return array_reduce(explode(';', $nestedPairs), function($result, $pair) {
            $keyVal = explode('=', $pair, 2);
            $key = trim(array_shift($keyVal));
            $val = trim(implode('=', $keyVal));
            if ($key !== '' && $val !== '') {
                $result[$key] = $val;
            }
            return $result;
        }, []);
    }
873242
private function removeMessage($messages)
    {
        if (! is_null($this->messageKey)) {
            unset($messages[$this->messageKey]);
            $this->messageKey = null;
        }

        return $messages;
    }
305475
protected function generateMessages(FileDescriptorProto $fileDescriptor, Traversable $messages, $parent = null)
    {
        $result = [];

        foreach ($messages as $message) {
            $entity        = $this->generateMessage($fileDescriptor, $message, $parent);
            $innerMessages = $message->getNestedTypeList();
            $innerEnums    = $message->getEnumTypeList();
            $innerParent   = ($parent !== null)
                ? $parent . '.' . $entity->getName()
                : $entity->getName();

            $result[] = $entity;

            if ($innerMessages) {
                $result = array_merge($result, $this->generateMessages($fileDescriptor, $innerMessages, $innerParent));
            }

            if ($innerEnums) {
                $result = array_merge($result, $this->generateEnums($fileDescriptor, $innerEnums, $innerParent));
            }
        }

        return $result;
    }
1290979
public function filterMessages(array $messages, array $supportedMessages, $canCreateNewMessages = false)
    {
        // Adding the keys `value` and `extension` to the messages, only if it is missing.
        $addValueToArray = function (array &$a) {
            foreach ($a as $k => $v) {
                if (false === isset($v['value'])) {
                    $a[$k]['value'] = '';
                }
                if (false === isset($v['extension'])) {
                    $a[$k]['extension'] = '';
                }
            }

            return $a;
        };

        $messagesArray = [];
        foreach ($messages as $key => $message) {
            if ($message instanceof FormzMessage) {
                $message = $message->toArray();
            }

            $messagesArray[$key] = $message;
        }

        $addValueToArray($messagesArray);
        $addValueToArray($supportedMessages);

        $messagesResult = $supportedMessages;

        ArrayUtility::mergeRecursiveWithOverrule(
            $messagesResult,
            $messagesArray,
            (bool)$canCreateNewMessages
        );

        return $messagesResult;
    }