protected function doLoadDatabaseTranslation($document, ClassMetadata $metadata, $locale, $fallback, $refresh)
    {
        $oid = spl_object_hash($document);

        $strategy = $this->dm->getTranslationStrategy($metadata->translator);

        try {
            $node = $this->session->getNode($this->getDocumentId($oid));
            if ($strategy->loadTranslation($document, $node, $metadata, $locale)) {
                return $locale;
            }
        } catch (PathNotFoundException $e) {
            // no node, document not persisted yet
            $node = null;
        }

        if (!$fallback) {
            $msg = sprintf('Document %s has no translation %s and fallback was not active', $this->getDocumentId($oid), $locale);

            throw new MissingTranslationException($msg);
        }

        $localesToTry = $this->dm->getLocaleChooserStrategy()->getFallbackLocales($document, $metadata, $locale);

        foreach ($localesToTry as $desiredLocale) {
            if (!$refresh && isset($this->documentLocales[$oid]['current']) && $desiredLocale == $this->documentLocales[$oid]['current']) {
                // noop, already the correct locale.
                return $desiredLocale;
            }
            // if there is a pending translation, it wins
            if ($this->doLoadPendingTranslation($document, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
            // try loading the translation with strategy if this is a stored document
            if ($node && $strategy->loadTranslation($document, $node, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
        }

        // we found no locale. so all translated fields are null and we
        // consider the locale to be the requested one
        $localeUsed = $locale;
        foreach ($metadata->translatableFields as $fieldName) {
            $value = ($metadata->mappings[$fieldName]['multivalue']) ? [] : null;
            $metadata->reflFields[$fieldName]->setValue($document, $value);
        }

        return $locale;
    }
protected function doLoadDatabaseTranslation($document, ClassMetadata $metadata, $locale, $fallback, $refresh)
    {
        $oid = spl_object_hash($document);

        $strategy = $this->dm->getTranslationStrategy($metadata->translator);

        try {
            $node = $this->session->getNode($this->getDocumentId($oid));
            if ($strategy->loadTranslation($document, $node, $metadata, $locale)) {
                return $locale;
            }
        } catch (PathNotFoundException $e) {
            // no node, document not persisted yet
            $node = null;
        }

        if (!$fallback) {
            $msg = sprintf('Document %s has no translation %s and fallback was not active', $this->getDocumentId($oid), $locale);

            throw new MissingTranslationException($msg);
        }

        $localesToTry = $this->dm->getLocaleChooserStrategy()->getFallbackLocales($document, $metadata, $locale);

        foreach ($localesToTry as $desiredLocale) {
            if (!$refresh && isset($this->documentLocales[$oid]['current']) && $desiredLocale == $this->documentLocales[$oid]['current']) {
                // noop, already the correct locale.
                return $desiredLocale;
            }
            // if there is a pending translation, it wins
            if ($this->doLoadPendingTranslation($document, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
            // try loading the translation with strategy if this is a stored document
            if ($node && $strategy->loadTranslation($document, $node, $metadata, $desiredLocale)) {
                return $desiredLocale;
            }
        }

        // we found no locale. so all translated fields are null and we
        // consider the locale to be the requested one
        $localeUsed = $locale;
        foreach ($metadata->translatableFields as $fieldName) {
            $value = ($metadata->mappings[$fieldName]['multivalue']) ? [] : null;
            $metadata->reflFields[$fieldName]->setValue($document, $value);
        }

        return $locale;
    }
protected function doLoadDatabaseTranslation ( $ document , ClassMetadata $ metadata , $ locale , $ fallback , $ refresh ) { $ oid = spl_object_hash ( $ document ) ; $ strategy = $ this -> dm -> getTranslationStrategy ( $ metadata -> translator ) ; try { $ node = $ this -> session -> getNode ( $ this -> getDocumentId ( $ oid ) ) ; if ( $ strategy -> loadTranslation ( $ document , $ node , $ metadata , $ locale ) ) { return $ locale ; } } catch ( PathNotFoundException $ e ) { // no node, document not persisted yet $ node = null ; } if ( ! $ fallback ) { $ msg = sprintf ( 'Document %s has no translation %s and fallback was not active' , $ this -> getDocumentId ( $ oid ) , $ locale ) ; throw new MissingTranslationException ( $ msg ) ; } $ localesToTry = $ this -> dm -> getLocaleChooserStrategy ( ) -> getFallbackLocales ( $ document , $ metadata , $ locale ) ; foreach ( $ localesToTry as $ desiredLocale ) { if ( ! $ refresh && isset ( $ this -> documentLocales [ $ oid ] [ 'current' ] ) && $ desiredLocale == $ this -> documentLocales [ $ oid ] [ 'current' ] ) { // noop, already the correct locale. return $ desiredLocale ; } // if there is a pending translation, it wins if ( $ this -> doLoadPendingTranslation ( $ document , $ metadata , $ desiredLocale ) ) { return $ desiredLocale ; } // try loading the translation with strategy if this is a stored document if ( $ node && $ strategy -> loadTranslation ( $ document , $ node , $ metadata , $ desiredLocale ) ) { return $ desiredLocale ; } } // we found no locale. so all translated fields are null and we // consider the locale to be the requested one $ localeUsed = $ locale ; foreach ( $ metadata -> translatableFields as $ fieldName ) { $ value = ( $ metadata -> mappings [ $ fieldName ] [ 'multivalue' ] ) ? [ ] : null ; $ metadata -> reflFields [ $ fieldName ] -> setValue ( $ document , $ value ) ; } return $ locale ; }
Attempt to load translation from the database.

If $fallback is true, goes over the locales as provided by the locale
chooser strategy to find the best language, each time first checking for
a pending translation. If no translation is found at all, the translated
fields are set to null and the requested locale is considered to be the
one found.

@param object        $document
@param ClassMetadata $metadata
@param string        $locale   The desired locale.
@param bool          $fallback Whether to perform language fallback.
@param bool          $refresh  Whether to force reloading the translation.

@throws MissingTranslationException if the translation in $locale is not
found and $fallback is false.

@return string The locale used

@see doLoadTranslation
Attempt to load translation from the database .