public function getCurrentLocale($document, ClassMetadata $metadata = null)
    {
        if (null === $metadata) {
            $metadata = $this->dm->getClassMetadata(get_class($document));
        }
        if (!$this->isDocumentTranslatable($metadata)) {
            return;
        }

        if ($metadata->localeMapping
            && (!$document instanceof Proxy || $document->__isInitialized())
        ) {
            $locale = $metadata->reflFields[$metadata->localeMapping]->getValue($document);
            if ($locale) {
                return $locale;
            }
        }

        $oid = spl_object_hash($document);
        if (isset($this->documentLocales[$oid]['current'])) {
            return $this->documentLocales[$oid]['current'];
        }

        return $this->dm->getLocaleChooserStrategy()->getLocale();
    }
public function getCurrentLocale($document, ClassMetadata $metadata = null)
    {
        if (null === $metadata) {
            $metadata = $this->dm->getClassMetadata(get_class($document));
        }
        if (!$this->isDocumentTranslatable($metadata)) {
            return;
        }

        if ($metadata->localeMapping
            && (!$document instanceof Proxy || $document->__isInitialized())
        ) {
            $locale = $metadata->reflFields[$metadata->localeMapping]->getValue($document);
            if ($locale) {
                return $locale;
            }
        }

        $oid = spl_object_hash($document);
        if (isset($this->documentLocales[$oid]['current'])) {
            return $this->documentLocales[$oid]['current'];
        }

        return $this->dm->getLocaleChooserStrategy()->getLocale();
    }
public function getCurrentLocale ( $ document , ClassMetadata $ metadata = null ) { if ( null === $ metadata ) { $ metadata = $ this -> dm -> getClassMetadata ( get_class ( $ document ) ) ; } if ( ! $ this -> isDocumentTranslatable ( $ metadata ) ) { return ; } if ( $ metadata -> localeMapping && ( ! $ document instanceof Proxy || $ document -> __isInitialized ( ) ) ) { $ locale = $ metadata -> reflFields [ $ metadata -> localeMapping ] -> getValue ( $ document ) ; if ( $ locale ) { return $ locale ; } } $ oid = spl_object_hash ( $ document ) ; if ( isset ( $ this -> documentLocales [ $ oid ] [ 'current' ] ) ) { return $ this -> documentLocales [ $ oid ] [ 'current' ] ; } return $ this -> dm -> getLocaleChooserStrategy ( ) -> getLocale ( ) ; }
Determine the current locale of a managed document.

If the document is not translatable, null is returned.

If the document is translatable and the locale is mapped onto a document
field, the value of that field is returned. Otherwise the UnitOfWork
information on locales for documents without a locale mapping is
consulted.

If nothing matches (for example when this is a detached document), the
default locale of the LocaleChooserStrategy is returned.

@param object        $document the managed document to get the locale for
@param ClassMetadata $metadata document metadata, optional

@return string|null the current locale of $document or null if it is not translatable
Determine the current locale of a managed document .