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;
    }
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;
    }
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 ; }
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
Get random Translation . If no translations are available return null .