Removes all unnecassary whitespaces and newlines from the given translations

@param array $translations

@return array   filtered translations
8317
public function filter($translations)
    {
        foreach ($translations as $pluginName => $pluginTranslations) {
            foreach ($pluginTranslations as $key => $translation) {

                $baseTranslation = '';
                if (isset($this->baseTranslations[$pluginName][$key])) {
                    $baseTranslation = $this->baseTranslations[$pluginName][$key];
                }

                // remove excessive line breaks (and leading/trailing whitespace) from translations
                $stringNoLineBreak = trim($translation);
                $stringNoLineBreak = str_replace("\r", "", $stringNoLineBreak); # remove useless carrige renturns
                $stringNoLineBreak = preg_replace('/(\n[ ]+)/', "\n", $stringNoLineBreak); # remove useless white spaces after line breaks
                $stringNoLineBreak = preg_replace('/([\n]{2,})/', "\n\n", $stringNoLineBreak); # remove excessive line breaks
                if (empty($baseTranslation) || !substr_count($baseTranslation, "\n")) {
                    $stringNoLineBreak = preg_replace("/[\n]+/", " ", $stringNoLineBreak); # remove all line breaks if english string doesn't contain any
                }
                $stringNoLineBreak = preg_replace('/([ ]{2,})/', " ", $stringNoLineBreak); # remove excessive white spaces again as there might be any now, after removing line breaks
                if ($translation !== $stringNoLineBreak) {
                    $this->filteredData[$pluginName][$key] = $translation;
                    $translations[$pluginName][$key] = $stringNoLineBreak;
                    continue;
                }
            }
        }

        return $translations;
    }
1232510
public function removeAliasPattern($pattern, $translation = null)
	{
		foreach (array_keys($this->patterns) as $patternKey)
		{
			if ($this->patterns[$patternKey]->matches($pattern, $translation))
			{
				unset($this->patterns[$patternKey]);
			}
		}
	}
608547
protected function filterTokens(array $tokens)
    {
        $filteredTokens = array_filter($tokens, function (Token $t) {
            return $t->getType() !== TokenType::Whitespace;
        });

        // Return the array values only, because array_filter preserves the keys
        return array_values($filteredTokens);
    }
1193420
public function removeTranslation(\Sulu\Bundle\Sales\ShippingBundle\Entity\ShippingStatusTranslation $translations)
    {
        $this->translations->removeElement($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);
        }
    }
514361
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            $translations = (array)$row['_i18n'];
            if (count($translations) === 0 && $row->get('_translations')) {
                return $row;
            }

            $result = [];
            foreach ($translations as $translation) {
                unset($translation['id']);
                $result[$translation['locale']] = $translation;
            }

            $row['_translations'] = $result;
            unset($row['_i18n']);
            if ($row instanceof EntityInterface) {
                $row->clean();
            }

            return $row;
        });
    }
1367179
private function cleanupGroupDelimiters(array &$tokens)
    {
        $indexes = $this->getUnmatchedGroupDelimiterIndexes($tokens);

        while (!empty($indexes)) {
            $lastIndex = array_pop($indexes);
            $token = $tokens[$lastIndex];
            unset($tokens[$lastIndex]);

            if ($token->type === Tokenizer::TOKEN_GROUP_BEGIN) {
                $this->addCorrection(
                    self::CORRECTION_UNMATCHED_GROUP_LEFT_DELIMITER_IGNORED,
                    $token
                );
            } else {
                $this->addCorrection(
                    self::CORRECTION_UNMATCHED_GROUP_RIGHT_DELIMITER_IGNORED,
                    $token
                );
            }
        }
    }
761202
public function setLines(array $lines)
    {
        $translator = $this->factory->getTranslator();

        if ($translator instanceof Translator) {
            $translator->setLines($lines);
        }
    }
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;
    }
1198068
public function setTranslations(array $translations)
    {
        if (gettype($translations) == 'array') {
            $translations = new ArrayCollection($translations);
        }

        $this->translations = $translations;

        return $this;
    }
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;
    }
558455
public function saveTranslations($translations)
    {
        $this->backup();

        foreach ($translations as $lang => $lines) {
            $filename = $this->languageFilesPath.DIRECTORY_SEPARATOR."$lang.json";

            ksort($lines);

            file_put_contents($filename, json_encode($lines, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
        }
    }
7839
public function getRecursiveTranslations(&$translationsArray)
    {
        // find all possible translations
        if (!$this->getTranslations()->isEmpty()) {
            foreach ($this->getTranslations() as $translation) {
                if ($translation) {
                    // if we already meet you stop and go on with the next
                    $translationsArray[$translation->getLocale()] = $translation;
                    $translation->getRecursiveTranslations($translationsArray);
                }
            }
        }

        // find all possible originals
        if (!$this->getOriginals()->isEmpty()) {
            foreach ($this->getOriginals() as $translation) {
                // if we already meet you stop and go on with the next
                if (array_key_exists($translation->getLocale(), $translationsArray)) {
                    return;
                }
                $translationsArray[$translation->getLocale()] = $translation;
                $translation->getRecursiveTranslations($translationsArray);
            }
        }
    }
777796
public function filter(array $locales)
    {
        $this->filtered = [];

        foreach ($locales as $locale) {
            $this->filterLocale($locale);
        }

        return $this->filtered;
    }
1248542
public function filterNotBlankTranslations()
    {
        return array_filter($this->getTranslations()->getArrayCopy(), function (TranslationInterface $translation) {
            $content = $translation->getContent();

            return !empty($content);
        });
    }
1061790
public function saveGettextFunctions(Translations $translations, array $options)
    {
        $functions = $options['functions'];
        $file = $options['file'];

        foreach ($this->getFunctions($options['constants']) as $function) {
            list($name, $line, $args) = $function;

            if (isset($options['lineOffset'])) {
                $line += $options['lineOffset'];
            }

            if (!isset($functions[$name])) {
                continue;
            }

            $domain = $context = $original = $plural = null;

            switch ($functions[$name]) {
                case 'noop':
                case 'gettext':
                    if (!isset($args[0])) {
                        continue 2;
                    }

                    $original = $args[0];
                    break;

                case 'ngettext':
                    if (!isset($args[1])) {
                        continue 2;
                    }

                    list($original, $plural) = $args;
                    break;

                case 'pgettext':
                    if (!isset($args[1])) {
                        continue 2;
                    }

                    list($context, $original) = $args;
                    break;

                case 'dgettext':
                    if (!isset($args[1])) {
                        continue 2;
                    }

                    list($domain, $original) = $args;
                    break;

                case 'dpgettext':
                    if (!isset($args[2])) {
                        continue 2;
                    }

                    list($domain, $context, $original) = $args;
                    break;

                case 'npgettext':
                    if (!isset($args[2])) {
                        continue 2;
                    }

                    list($context, $original, $plural) = $args;
                    break;

                case 'dnpgettext':
                    if (!isset($args[3])) {
                        continue 2;
                    }

                    list($domain, $context, $original, $plural) = $args;
                    break;

                case 'dngettext':
                    if (!isset($args[2])) {
                        continue 2;
                    }

                    list($domain, $original, $plural) = $args;
                    break;

                default:
                    throw new Exception(sprintf('Not valid function %s', $functions[$name]));
            }

            if ((string)$original === '') {
                continue;
            }

            $isDefaultDomain = $domain === null;
            $isMatchingDomain = $domain === $translations->getDomain();

            if (!empty($options['domainOnly']) && $isDefaultDomain) {
                // If we want to find translations for a specific domain, skip default domain messages
                continue;
            }

            if (!$isDefaultDomain && !$isMatchingDomain) {
                continue;
            }

            $translation = $translations->insert($context, $original, $plural);
            $translation->addReference($file, $line);

            if (isset($function[3])) {
                foreach ($function[3] as $extractedComment) {
                    $translation->addExtractedComment($extractedComment);
                }
            }
        }
    }
748575
private static function fromArray(array $messages, Translations $translations)
    {
        if (!empty($messages['domain'])) {
            $translations->setDomain($messages['domain']);
        }

        if (!empty($messages['plural-forms'])) {
            $translations->setHeader(Translations::HEADER_PLURAL, $messages['plural-forms']);
        }

        foreach ($messages['messages'] as $context => $contextTranslations) {
            foreach ($contextTranslations as $original => $value) {
                if ($context === '' && $original === '') {
                    self::extractHeaders(is_array($value) ? array_shift($value) : $value, $translations);
                    continue;
                }

                $translation = $translations->insert($context, $original);

                if (is_array($value)) {
                    $translation->setTranslation(array_shift($value));
                    $translation->setPluralTranslations($value);
                } else {
                    $translation->setTranslation($value);
                }
            }
        }
    }