Extract the entries from a dictionary.

@param array        $messages
@param Translations $translations
974033
private static function fromArray(array $messages, Translations $translations)
    {
        foreach ($messages as $original => $translation) {
            if ($original === '') {
                self::extractHeaders($translation, $translations);
                continue;
            }

            $translations->insert(null, $original)->setTranslation($translation);
        }
    }
1038603
protected function write($messages): void
    {
        if (! \is_array($messages)) {
            $messages = [$messages];
        }

        foreach ($messages as $i => $message) {
            $messages[$i] = '    - ' . $message;
        }

        $this->io->writeError($messages, true, IOInterface::VERBOSE);
    }
405886
protected function normaliseMessages($messages, $locale)
    {
        foreach ($messages as $key => $value) {
            $messages[$key] = $this->normaliseMessage($key, $value, $locale);
        }
        return $messages;
    }
133205
public function setTranslationsForLanguage(array $messages, $language)
    {
        foreach ($messages as $key => $value) {
            $this->setTranslation($key, $value, $language);
        }
    }
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;
    }
50587
public function filter($translations)
    {
        $cleanedTranslations = array();

        foreach ($translations as $pluginName => $pluginTranslations) {

            if (empty($this->baseTranslations[$pluginName])) {
                $this->filteredData[$pluginName] = $pluginTranslations;
                continue;
            }

            foreach ($pluginTranslations as $key => $translation) {
                if (isset($this->baseTranslations[$pluginName][$key])) {
                    $cleanedTranslations[$pluginName][$key] = $translation;
                }
            }

            if (!empty($cleanedTranslations[$pluginName])) {
                $diff = array_diff($translations[$pluginName], $cleanedTranslations[$pluginName]);
            } else {
                $diff = $translations[$pluginName];
            }
            if (!empty($diff)) {
                $this->filteredData[$pluginName] = $diff;
            }
        }

        return $cleanedTranslations;
    }
462624
public function getTranslatedLabels(array $languages)
    {
        $labels = [];
        foreach ($languages as $language) {

            foreach (Config::getCustomModelTemplates() as $key => $properties) {
                $label = $this->makeModelLabel($key, $properties, false, $language);
                $labels[$language][] = $label;
            }
        }

        return $labels;
    }
1100458
private function getLanguagesNumbers(array $languages): array
    {
        $languagesNumbers = array_column($languages, 'id');

        return array_combine($languagesNumbers, array_fill_keys($languagesNumbers, false));
    }
189273
private function extractLanguageCodesFromMask(int $languageMask, array $allLanguages, &$missing = [])
    {
        $exp = 2;
        $result = [];

        // Decomposition of $languageMask into its binary components to extract language codes
        while ($exp <= $languageMask) {
            if ($languageMask & $exp) {
                if (isset($allLanguages[$exp])) {
                    $result[] = $allLanguages[$exp]->languageCode;
                } else {
                    $missing[] = $exp;
                }
            }

            $exp *= 2;
        }

        return $result;
    }
763843
private function loadTranslationMessages($language)
    {
        // Reset any previous translations if any
        $this->moduleManager->clearTranslations();
        $this->translator->reset();

        // Now load new ones
        $this->moduleManager->loadAllTranslations($language);
        $this->translator->extend($this->moduleManager->getTranslations());
    }
50384
public function setMessages(array $messages)
    {
        foreach ($messages as $key => $message) {
            $this->setMessage($message, $key);
        }
        return $this;
    }
553754
private function addIndentationToMessages($messages)
    {
        if (is_array($messages)) {
            array_walk(
                $messages,
                function ($message) {
                    return $this->indentation . $message;
                }
            );
            return $messages;
        } else {
            $messages = $this->indentation . $messages;
            return $messages;
        }
    }
1232898
protected function _log($messages)
    {
        if (!is_array($messages)) {
            $messages = [$messages];
        }
        foreach ($messages as $message) {
            file_put_contents(static::$logFile, date('d.m.Y H:i:s') . ' - ' . $message . PHP_EOL, FILE_APPEND | LOCK_EX);
        }
    }
71123
private function getMessageAckIds(array $messages)
    {
        $ackIds = [];
        foreach ($messages as $message) {
            $ackIds[] = $message->ackId();
        }

        return $ackIds;
    }
796215
private function normalizePropertyTranslations(array $translations)
    {
        $maxLength = 0;

        foreach ($translations as $property => $translation) {
            $length = strlen($property);

            if ($length > $maxLength) {
                $maxLength = $length;
            }
        }
        foreach ($translations as $property => $translation) {
            $translations[$property] = str_repeat(' ', $maxLength - strlen($property)).$translation;
        }

        ksort($translations);

        return $translations;
    }
43116
protected function _addMessage(array &$messages, array $item)
    {
        if (empty($item['ids']['singular']) && empty($item['ids']['plural'])) {
            return;
        }

        $singular = stripcslashes($item['ids']['singular']);
        $context = isset($item['context']) ? $item['context'] : null;
        $translation = $item['translated'];

        if (is_array($translation)) {
            $translation = $translation[0];
        }

        $translation = stripcslashes($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 = 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;
            }
        }
    }
703815
public function filter($translations)
    {
        foreach ($translations as $pluginName => $pluginTranslations) {
            foreach ($pluginTranslations as $key => $translation) {

                if (isset($this->baseTranslations[$pluginName][$key]) &&
                    $this->baseTranslations[$pluginName][$key] != Translate::clean($this->baseTranslations[$pluginName][$key])) {
                    continue; // skip if base translation already contains encoded entities
                }

                // remove encoded entities
                $decoded = Translate::clean($translation);
                if ($translation != $decoded) {
                    $this->filteredData[$pluginName][$key] = $translation;
                    $translations[$pluginName][$key] = $decoded;
                    continue;
                }

            }
        }

        return $translations;
    }