Get random Translation. If no translations are available, return null.

@param array $domains
@param array $languages

@return Translation|null

@throws Exception You cannot search missing translations by master language
973707
public function getRandomMissingTranslation(
        array $domains = [],
        array $languages = []
    ) : ? Translation {
        if (in_array($this->masterLanguage, $languages)) {
            throw new Exception('You cannot search by master language missing translations');
        }

        $candidates = [];
        $masterKeys = $this->getKeys(
            $domains,
            [$this->masterLanguage]
        );

        $languages = $languages ?: $this->getAvailableLanguages();

        foreach ($languages as $language) {
            $languageKeys = $this->getKeys(
                $domains,
                [$language]
            );

            $missingKeys = array_diff(
                $masterKeys,
                $languageKeys
            );
            foreach ($missingKeys as $missingKey) {
                $candidates[] = [
                    'language' => $language,
                    'key' => $missingKey,
                ];
            }
        }

        if (empty($candidates)) {
            return null;
        }

        $candidateKey = array_rand($candidates);
        $candidate = $candidates[$candidateKey];
        $masterCandidate = $this->getTranslation(
            $this->masterLanguage,
            $candidate['key']
        );

        $candidateTranslation = Translation::create(
            $candidate['key'],
            '',
            $candidate['language']
        );

        $candidateTranslation->setStructure($masterCandidate->getStructure());
        $candidateTranslation->setMasterTranslation($masterCandidate);

        return $candidateTranslation;
    }
613806
public function setSupportedLanguages(array $languages)
    {
        $this->languages = $languages;
        $this->fallbackLanguage = reset($languages);

        return $this;
    }
133205
public function setTranslationsForLanguage(array $messages, $language)
    {
        foreach ($messages as $key => $value) {
            $this->setTranslation($key, $value, $language);
        }
    }
1359001
private function translate(array $translations)
    {
        foreach ($translations as $key => $part) {
            if (is_array($part)) {
                $translations[$key] = $this->translate($part);
            } else {
                $translations[$key] = $this->translateText($part);
            }
        }

        return $translations;
    }
275799
public function get( array $languageIds )
	{
		$i18nPaths = $this->aimeos->get()->getI18nPaths();

		foreach( $languageIds as $langid )
		{
			if( !isset( $this->i18n[$langid] ) )
			{
				$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $langid );

				if( $this->config->get( 'shop.apc_enabled', false ) == true ) {
					$i18n = new \Aimeos\MW\Translation\Decorator\APC( $i18n, $this->config->get( 'shop.apc_prefix', 'laravel:' ) );
				}

				if( $this->config->has( 'shop.i18n.' . $langid ) ) {
					$i18n = new \Aimeos\MW\Translation\Decorator\Memory( $i18n, $this->config->get( 'shop.i18n.' . $langid ) );
				}

				$this->i18n[$langid] = $i18n;
			}
		}

		return $this->i18n;
	}
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'];
    }
117658
public static function get(LanguageInterface $language = null, $application_name = null) {
		if (!isset(self::$translation[$language->name_short]) OR self::$translation[$language->name_short]->application_name != $application_name) {
			self::$translation[$language->name_short] = new self($language, $application_name);
		}

		return self::$translation[$language->name_short];
	}
1227969
public function getTranslations(
        array $domains = [],
        array $languages = [],
        callable $filter = null
    ) : array {
        $translations = array_filter(
            $this->translations,
            function (Translation $translation) {
                return $translation->getValue() != '';
            }
        );

        if (is_callable($filter)) {
            $translations = array_filter(
                $translations,
                $filter
            );
        }

        return $translations;
    }
649095
public function getTranslationsByLocalesAndDomains($locales, $domains)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();
        $qb
            ->select('t')
            ->from('KunstmaanTranslatorBundle:Translation', 't')
            ->andWhere('t.status != :statusstring')
            ->setParameter('statusstring', Translation::STATUS_DISABLED)
            ->orderBy('t.domain', 'ASC')
            ->addOrderBy('t.keyword', 'ASC');

        if (count($locales) > 0) {
            $qb->andWhere($qb->expr()->in('t.locale', $locales));
        }

        if (count($domains) > 0) {
            $qb->andWhere($qb->expr()->in('t.domain', $domains));
        }

        $result = $qb
            ->getQuery()
            ->getResult();

        return $result;
    }
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
        );
    }
158915
public function trans($id, array $parameters = [], $domain = null, $locale = null)
    {
        if (null === $domain) {
            $domain = 'messages';
        }

        $format = $this->getCatalogue($locale)->get((string) $id, $domain);

        if ($format instanceof Closure) {
            // @codeCoverageIgnoreStart
            try {
                $count = (new ReflectionFunction($format))->getNumberOfRequiredParameters();
            } catch (ReflectionException $exception) {
                $count = 0;
            }
            // @codeCoverageIgnoreEnd

            return $format(
                ...array_values($parameters),
                ...array_fill(0, max(0, $count - count($parameters)), null)
            );
        }

        return parent::trans($id, $parameters, $domain, $locale);
    }
423946
public static function fromArrays(array $arrays): ArrayTranslatorProvider {
        $ret = new static([]);

        foreach ($arrays as $lang => $translations) {
            if (is_array($translations)) {
                $ret->translators[$lang] = new Translator($translations, $lang);
            } else {
                throw new \InvalidArgumentException('$arrays must have string[][] type');
            }
        }

        return $ret;
    }
1050965
public function export($domains = [], $force = null)
    {
        foreach ($this->formExportList($domains, $force) as $file => $translations) {
            if (!file_exists($file)) {
                (new Filesystem())->touch($file);
            }

            $currentTranslations = $this->parser->parse(file_get_contents($file)) ?? [];

            $currentTranslations = $this->flatten($currentTranslations);

            $translations = array_replace_recursive($currentTranslations, $translations);

            $this->exporter->export($file, $translations);
        }

        $this->translationManager->save($this->refresh);
        $this->refresh = [];
    }
244883
public function getTranslation($lang, $create = false)
    {
        foreach ($this->translations as $translation) {
            if ($lang == $translation->getLang()) {
                return $translation;
            }
        }

        if ($create) {
            $class = $this->getTranslationClass();

            /** @var TranslationInterface $translation */
            $translation = new $class();
            $translation->setLang($lang);
            $this->addTranslation($translation);

            return $translation;
        }

        return null;
    }
431823
protected function t($key, array $parameters = [], $domain = null, $locale = null)
    {
        return $this->getContainer()->get('translator')->trans($key, $parameters, $domain, $locale);
    }
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);
    }
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'];
        }
    }