public function translate($entity, $locale)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        if($metadata === null) {
            return null;
        }

        //translation data is stored inside the object
        if($locale === $this->defaultLocale) {
            return;
        }

        $accessor = PropertyAccess::createPropertyAccessor();   
        if($metadata !== null) {
            foreach($metadata->getProperties() as $property) {
                $strategy = $this->strategyResolver->getStrategy($property->getStrategy());
                $value = $strategy->getTranslation($entity, $property, $locale, $metadata);
                $accessor->setValue($entity, $property->getName(), $value);
            }
        }
    }
public function translate($entity, $locale)
    {
        $metadata = $this->metadataCollection->getMetadata($entity);
        if($metadata === null) {
            return null;
        }

        //translation data is stored inside the object
        if($locale === $this->defaultLocale) {
            return;
        }

        $accessor = PropertyAccess::createPropertyAccessor();   
        if($metadata !== null) {
            foreach($metadata->getProperties() as $property) {
                $strategy = $this->strategyResolver->getStrategy($property->getStrategy());
                $value = $strategy->getTranslation($entity, $property, $locale, $metadata);
                $accessor->setValue($entity, $property->getName(), $value);
            }
        }
    }
public function translate ( $ entity , $ locale ) { $ metadata = $ this -> metadataCollection -> getMetadata ( $ entity ) ; if ( $ metadata === null ) { return null ; } //translation data is stored inside the object if ( $ locale === $ this -> defaultLocale ) { return ; } $ accessor = PropertyAccess :: createPropertyAccessor ( ) ; if ( $ metadata !== null ) { foreach ( $ metadata -> getProperties ( ) as $ property ) { $ strategy = $ this -> strategyResolver -> getStrategy ( $ property -> getStrategy ( ) ) ; $ value = $ strategy -> getTranslation ( $ entity , $ property , $ locale , $ metadata ) ; $ accessor -> setValue ( $ entity , $ property -> getName ( ) , $ value ) ; } } }
Translate an entity. All stored translation data will be applied to this object. It should be called only inside the
doctrine postLoad hook, because it doesn't handle recursive connections.

@param $entity
@param $locale
@return null
@throws \Exception
Translate an entity . All stored translation data will be applied to this object . It should be called only inside the doctrine postLoad hook because it doesn t handle recursive connections .