Calculate difference between the requested data and the obtained

@param  array | string $locale
@param  array | string $domain
@param  array          $catalogs
@return array | null   [locale, domain] Need to request | Need no request
426967
protected function calculateRequestDiff($locale, $domain, array $catalogs) {
		$domain = array_flip((array) $domain);
		$locale = array_flip((array) $locale);
		
		$diffLocale = array_diff_key($locale, $catalogs);
		$diffDomain = empty($diffLocale) ? [] : $domain;
		
		foreach ($catalogs as $localeId => $catalog) {
			$diff = array_diff_key($domain, $catalog);
			
			if (! empty($diff)) {
				$diffDomain           += $diff;
				$diffLocale[$localeId] = true;
			}
		}
		
		if (empty($diffLocale)) {
			return;
		}
		
		return [
			$this->normalizeRequestDiff($diffLocale),
			$this->normalizeRequestDiff($diffDomain)
		];
	}
732855
public function trans($id, array $parameters = [], $domain = null, $locale = null)
    {
        if (null === $locale) {
            $locale = $this->getLocale();
        }

        if (null === $domain) {
            $domain = 'messages';
        }

        if (!isset($this->catalogues[$locale])) {
            $this->loadCatalogue($locale);
        }

        // Change translation domain to 'messages' if a translation can't be found in the
        // current domain
        if ('messages' !== $domain && false === $this->catalogues[$locale]->has((string) $id, $domain)) {
            $domain = 'messages';
        }

        return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
    }
1340000
protected function prepareCacheId($locale, $domain) {
		if (is_array($locale)) {
			$list = [];
			
			// many locales to many domains
			if (is_array($domain)) {
				foreach ($locale as $part1) {
					foreach ($domain as $part2) {
						$list[] = $part1 . '_' . $part2;
					}
				}
				
				return $list;
			}
			
			// many locales to one domain
			foreach ($locale as $part) {
				$list[] = $part1 . '_' . $domain;
			}
			
			return $list;
		}
		
		// one locale to many domains
		if (is_array($domain)) {
			$list = [];
			
			foreach ($domain as $part) {
				$list[] = $locale . '_' . $part;
			}
			
			return $list;
		}
		
		// one locale to one domain
		return $locale . '_' . $domain;
	}
987961
private function getCatalogue($locale)
    {
        if (empty($this->catalogues[$locale])) {
            $this->loadCatalogue($locale, $this->dir);
        }

        return $this->catalogues[$locale];
    }
427528
public function getAllByLocaleAndDomain($locale, $domain)
    {
        return $this->createQueryBuilder('tu')
            ->select('tu, te')
            ->leftJoin('tu.translations', 'te')
            ->where('tu.domain = :domain')
            ->andWhere('te.locale = :locale')
            ->setParameter('domain', $domain)
            ->setParameter('locale', $locale)
            ->getQuery()
            ->getArrayResult();
    }
1317337
public function instance($domain = 'app', $locale = null)
    {
        $locale = $locale ?: $this->locale;

        // The ID code is something like: 'en/system', 'en/app' or 'en/file_manager'
        $id = $locale .'/' .$domain;

        // Returns the Language domain instance, if it already exists.
        if (isset($this->instances[$id])) return $this->instances[$id];

        return $this->instances[$id] = new Language($this, $domain, $locale);
    }
946963
public function getTranslations(string $page, ?string $locale = null): array
    {
        $config = $this->getPageConfig($page);

        $messages = [];
        $catalogue = $this->translatorBag->getCatalogue($locale);

        foreach ($config as $domain => $keys) {
            foreach ($this->getMessages($catalogue, $domain, $keys) as $domainLocale => $messageStrings) {
                if (!$messageStrings) {
                    continue;
                }

                if (!array_key_exists($domainLocale, $messages)) {
                    $messages[$domainLocale] = [];
                }

                $messages[$domainLocale][$domain] = $messageStrings;
            }
        }

        return $messages;

    }
526035
public function getYaml($messages, $locale)
    {
        $entities = $this->denormaliseMessages($messages);
        $content = $this->getDumper()->dump([
            $locale => $entities
        ], 99);
        return $content;
    }
1100120
protected function parseTokens($tokens, MessageCatalogue $catalog)
    {
        $tokenIterator = new \ArrayIterator($tokens);

        for ($key = 0; $key < $tokenIterator->count(); ++$key) {
            foreach ($this->sequences as $sequence) {
                $message = '';
                $domain = 'messages';
                $tokenIterator->seek($key);

                foreach ($sequence as $sequenceKey => $item) {
                    $this->seekToNextRelevantToken($tokenIterator);

                    if ($this->normalizeToken($tokenIterator->current()) === $item) {
                        $tokenIterator->next();
                        continue;
                    } elseif (self::MESSAGE_TOKEN === $item) {
                        $message = $this->getValue($tokenIterator);

                        if (\count($sequence) === ($sequenceKey + 1)) {
                            break;
                        }
                    } elseif (self::METHOD_ARGUMENTS_TOKEN === $item) {
                        $this->skipMethodArgument($tokenIterator);
                    } elseif (self::DOMAIN_TOKEN === $item) {
                        $domainToken = $this->getValue($tokenIterator);
                        if ('' !== $domainToken) {
                            $domain = $domainToken;
                        }

                        break;
                    } else {
                        break;
                    }
                }

                if ($message) {
                    $catalog->set($message, $this->prefix.$message, $domain);
                    break;
                }
            }
        }
    }
231060
protected function initCatalogForManyDomains($locale, $domains) {
		foreach ($domains as $domain) {
			$this->initCatalog($locale, $domain);
		}
	}
1235323
protected function getCatalogContent($locale, $domain) {
		$path = $this->getCatalogPath($locale, $domain);
		
		if (! is_file($path)) {
			return false;
		}
		
		if (! is_readable($path)) {
			throw new ReadError('Catalog file: "' . $path . '" exists but can\'t be read');
		}
		
		$result = file_get_contents($path);
		
		if ($result === false) {
			throw new ReadError('Error has occurred while reading the file: "' . $path . '"');
		}
		
		$this->lastFilePath = $path;
		
		return $result;
	}
356862
public function getTranslations(
        array $domains = [],
        array $languages = [],
        callable $filter = null
    ) : array {
        return $this
            ->repositoryCollection
            ->getTranslations(
                $domains,
                $languages,
                $filter
            );
    }
434376
protected function importBundlesTranslationFiles(array $locales, array $domains, $global = false)
    {
        $bundles = $this->getApplication()->getKernel()->getBundles();

        foreach ($bundles as $bundle) {
            $this->importBundleTranslationFiles($bundle, $locales, $domains, $global);
        }
    }
1093834
public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null)
    {
        $sortColumn = isset($filters['sidx']) ? $filters['sidx'] : 'id';
        $order = isset($filters['sord']) ? $filters['sord'] : 'ASC';

        $sortColumn = ucfirst($sortColumn);

        $query = TransUnitQuery::create()
            ->select('Id')
        ;

        $this->addTransUnitFilters($query, $filters);
        $this->addTranslationFilter($query, $locales, $filters);

        $ids = $query
            ->orderBy($sortColumn, $order)
            ->offset($rows * ($page - 1))
            ->limit($rows)
            ->find($this->getConnection())
        ;

        $transUnits = array();

        if (count($ids) > 0) {
            $unitsData = TransUnitQuery::create()
                ->filterById($ids, Criteria::IN)
                ->joinWith('Translation')
                ->useTranslationQuery()
                    ->filterByLocale($locales, Criteria::IN)
                ->endUse()
                ->orderBy($sortColumn, $order)
                ->setFormatter(ModelCriteria::FORMAT_ARRAY)
                ->find($this->getConnection())
            ;

            $transUnits = $this->filterTransUnitData($unitsData);
        }

        return $transUnits;
    }
560213
public function getTranslations($locale, $domain)
    {
        $conn = $this->getEntityManager()->getConnection();
        $stmt = $conn->executeQuery(
            'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?',
            [$locale, $domain]
        );
        while ($row = $stmt->fetch()) {
            yield $row['message'] => $row['translation'];
        }
    }
428229
protected function initCatalogsForManyLocales($locales, $domain) {
		foreach ($locales as $locale) {
			$this->initCatalogsForSingleLocale($locale, $domain);
		}
	}
344787
public function findAllNotDisabled($locale, $domain = null)
    {
        $qb = $this->createQueryBuilder('t');
        $qb
            ->select('t')
            ->where('t.locale = :locale')
            ->andWhere('t.status != :statusstring')
            ->setParameter('statusstring', Translation::STATUS_DISABLED)
            ->setParameter('locale', $locale);
        if (!\is_null($domain) && !empty($domain)) {
            $qb->andWhere('t.domain = :tdomain')
                ->setParameter('tdomain', $domain);
        }

        return $qb->getQuery()->getResult();
    }