Doctrine\ODM\PHPCR\UnitOfWork::getCurrentLocale PHP Method

getCurrentLocale() public method

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.
public getCurrentLocale ( object $document, ClassMetadata $metadata = null ) : string | null
$document object the managed document to get the locale for
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata document metadata, optional
return string | null the current locale of $document or null if it is not translatable
    public function getCurrentLocale($document, ClassMetadata $metadata = null)
    {
        if (null === $metadata) {
            $metadata = $this->dm->getClassMetadata(get_class($document));
        }
        if (!$this->isDocumentTranslatable($metadata)) {
            return null;
        }
        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();
    }
UnitOfWork