Needed when translations for the part of the alias are the same for multiple languages.
In that case we need to ensure that more prioritized language is chosen.

@param array $translations

@return array
496646
private function sortTranslationsByPrioritizedLanguages(array $translations)
    {
        $sortedTranslations = array();
        foreach ($this->settings['prioritizedLanguageList'] as $languageCode) {
            if (isset($translations[$languageCode])) {
                $sortedTranslations[] = array(
                    'lang' => $languageCode,
                    'text' => $translations[$languageCode],
                );
                unset($translations[$languageCode]);
            }
        }

        foreach ($translations as $languageCode => $translation) {
            $sortedTranslations[] = array(
                'lang' => $languageCode,
                'text' => $translation,
            );
        }

        return $sortedTranslations;
    }
797027
public static function generate(Translations $translations, array $options = [])
    {
        $options += static::$options;

        return self::toArray($translations, $options['includeHeaders'], true);
    }
777796
public function filter(array $locales)
    {
        $this->filtered = [];

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

        return $this->filtered;
    }
30912
public static function extract(array $content, Translations $translations)
    {
        $messages = \current($content);
        $headers = $messages[''] ?? null;
        unset($messages['']);

        if (!empty($headers['domain'])) {
            $translations->setDomain($headers['domain']);
        }

        if (!empty($headers['lang'])) {
            $translations->setLanguage($headers['lang']);
        }

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

        $context_glue = '\u0004';

        foreach ($messages as $key => $translation) {
            $key = \explode($context_glue, $key);
            $context = isset($key[1]) ? \array_shift($key) : '';

            $translations->insert($context, \array_shift($key))
                ->setTranslation(\array_shift($translation))
                ->setPluralTranslations($translation);
        }
    }
1159811
private function translateChoices(array $vars): array
    {
        $domain = $vars['choice_translation_domain'];
        if ($domain === false)
            return $vars['choices'];
        if (empty($domain))
            $domain = $vars['translation_domain'];
        if ($domain === false)
            return $vars['choices'];
        if (empty($domain))
            $domain = $this->getTemplateManager()->getTranslationDomain();
        if ($domain === false)
            return $vars['choices'];

        foreach($vars['choices'] as $choice)
        {
            if (is_object($choice->data))
                return $vars['choices'];
            $choice->label = $this->getTranslator()->trans($choice->label, [], $domain);
        }

        return $vars['choices'];
    }
999234
protected function addTranslations(array $translations)
    {
        $domain = $translations['domain'] ?? '';

        //Set the first domain loaded as default domain
        if ($this->domain === null) {
            $this->domain = $domain;
        }

        if (isset($this->dictionary[$domain])) {
            $this->dictionary[$domain] = \array_replace_recursive($this->dictionary[$domain], $translations['messages']);

            return;
        }

        if (!empty($translations['plural-forms'])) {
            [$count, $code] = \array_map('trim', \explode(';', $translations['plural-forms'], 2));

            // extract just the expression turn 'n' into a php variable '$n'.
            // Slap on a return keyword and semicolon at the end.
            $this->plurals[$domain] = [
                'count' => (int) \str_replace('nplurals=', '', $count),
                'code' => \str_replace('plural=', 'return ', \str_replace('n', '$n', $code)).';',
            ];
        }

        $this->dictionary[$domain] = $translations['messages'];
    }
685529
public function loadTranslations($languages)
    {
        $languages = (array)$languages;

        foreach ($languages as $language) {
            $this->getTranslation($language);
        }
    }
258295
private static function getTranslations(array $words)
    {
        $result = array();
        foreach ($words as $i) {
            $result = array_merge($result, array(ucfirst($i), strtoupper($i), strtolower($i)));
        }

        return $result;
    }
91728
private static function extractHeaders($headers, Translations $translations)
    {
        $headers = explode("\n", $headers);
        $currentHeader = null;

        foreach ($headers as $line) {
            $line = self::convertString($line);

            if ($line === '') {
                continue;
            }

            if (self::isHeaderDefinition($line)) {
                $header = \array_map('\trim', \explode(':', $line, 2));
                $currentHeader = $header[0];
                $translations->setHeader($currentHeader, $header[1]);
            } else {
                $entry = $translations->getHeader($currentHeader);
                $translations->setHeader($currentHeader, $entry.$line);
            }
        }
    }
1349249
public function filter($translations)
    {
        $translationsBefore = $translations;

        foreach ($translations as $plugin => &$pluginTranslations) {

            $pluginTranslations = array_filter($pluginTranslations, function ($value) {
                return !empty($value) && '' != trim($value);
            });

            $diff = array_diff($translationsBefore[$plugin], $pluginTranslations);
            if (!empty($diff)) {
                $this->filteredData[$plugin] = $diff;
            }
        }

        // remove plugins without translations
        $translations = array_filter($translations, function ($value) {
            return !empty($value) && count($value);
        });

        return $translations;
    }
325199
private function getTranslations($lang) {
    if (!isset($this->translations[$lang])) {
      $messageFile = $this->localeDir."/messages_".$lang.".php";
      if (file_exists($messageFile)) {
        require_once($messageFile);
        // store for later reference
        $this->translations[$lang] = ${"messages_$lang"};
      }
      else {
        $this->translations[$lang] = [];
      }
    }
    return $this->translations[$lang];
  }
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;
    }
721332
public function transform($translation)
    {
        $translation = $this->entityToArray(BlockTranslation::class, $translation);
        return [
            'id'           => (int) $translation['id'],
            'langCode'     => $translation['lang_code'],
            'title'        => $translation['title'],
            'body'         => $translation['body'],
            'customFields' => $this->transformCustomFields($translation),
            'isActive'     => (bool) $translation['is_active'],
            'createdAt'    => $translation['created_at'],
            'updatedAt'    => $translation['updated_at'],
        ];
    }
965880
protected function mapTranslationDataResult(array $translationData): array
    {
        $result = [];
        foreach ($translationData as $data) {
            $result[] = TranslationData::createFromArray($data);
        }
        return $result;
    }
1044921
public function alias($lang, $aliases)
    {
        $lang = strtolower($lang);

        if (!is_array($aliases)) {
            $aliases = [$aliases];
        }

        $aliases = array_map('strtolower', $aliases);

        $this->aliases[$lang] = array_unique(
            array_merge(Arr::get($this->aliases, $lang, []), $aliases)
        );

        return $this;
    }
67676
public function addTranslationArray(array $translations, $language)
    {
        $language = (string) $language;
        if ($language === '') {
            throw new \InvalidArgumentException('$language cannot be empty');
        }

        if (!isset($this->translations[$language])) {
            $this->translations[$language] = [];
        }

        $this->translations[$language] = array_merge(
            $this->translations[$language],
            $translations
        );
    }
306887
protected function prepareTranslations($translations) {
        $return = [];

        foreach($translations as $translation)
            $return[$translation['locale']][!is_null($translation['group']) ? $translation['group']. '.' . $translation['key'] : ''. $translation['key']] = $translation['value'];

       return $return;
    }