Convert entity to a formatted array with translations.
@param  Entity  $entity
@param  array $locales
@param  integer $depth
@return array
502086
public function toArrayI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($property->get('i18n')) {
				foreach($locales as $locale) {
					if($entity->getDefinition()->property($name)->get('many')) {
						foreach($entity->get($name, $locale)->all() as $k=>$v)
							$res[$name][$locale][$k] = $this->propertyToArray($v, $property);
					}
					else
						$res[$name][$locale] = $this->propertyToArray($entity->get($name, $locale), $property);
				}
			}
			elseif($entity->getDefinition()->property($name)->get('type') == 'entity') {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name) as $entity)
						$res[$name][] = $entity->toArrayI18N($locales, $depth-1);
				}
				else
					$res[$name] = $entity->toArrayI18N($depth-1);
			}
			elseif($entity->getDefinition()->property($name)->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name)->all() as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
1350515
protected function build(PackageVersionEntity $packageVersion, array $locales)
    {
        $result = [];
        $app = Application::getFacadeApplication();
        try {
            $total = (int) $app->make(TranslatablePlaceRepository::class)
                ->createQueryBuilder('p')
                    ->select('count(p.translatable)')
                    ->where('p.packageVersion = :packageVersion')->setParameter('packageVersion', $packageVersion)
                    ->getQuery()->getSingleScalarResult();
        } catch (NoResultException $x) {
            $total = 0;
        }
        foreach ($locales as $locale) {
            $result[$locale->getID()] = StatsEntity::create($packageVersion, $locale)->setTotal($total);
        }
        $em = $this->getEntityManager();
        $connection = $em->getConnection();
        if ($total > 0) {
            $q = [$packageVersion->getID()];
            $w = [];
            foreach ($locales as $locale) {
                $w[] = 't.locale = ?';
                $q[] = $locale->getID();
            }
            $dateTimeFormatString = $connection->getDatabasePlatform()->getDateTimeFormatString();
            $rs = $connection->executeQuery(
                '
                    select
                        t.locale,
                        count(t.translatable) as translated,
                        max(t.currentSince) as updated
                    from
                        CommunityTranslationTranslatablePlaces as p
                        inner join CommunityTranslationTranslations as t on p.translatable = t.translatable and 1 = t.current
                    where
                        p.packageVersion = ?
                        and (' . implode(' or ', $w) . ')
                    group by
                        t.locale
                ',
                $q
            );
            while (($row = $rs->fetch()) !== false) {
                if (!empty($row['translated'])) {
                    $result[$row['locale']]
                        ->setTranslated($row['translated'])
                        ->setLastUpdated(DateTime::createFromFormat($dateTimeFormatString, $row['updated']));
                }
            }
            $rs->closeCursor();
        }
        foreach ($result as $stats) {
            $em->persist($stats);
        }
        $em->flush();

        return array_values($result);
    }
102761
public function toArrayRawI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($property->get('i18n')) {
				foreach($locales as $locale) {
					if($entity->getDefinition()->property($name)->get('many'))
						$res[$name][$locale] = $entity->get($name, $locale)->all();
					else
						$res[$name][$locale] = $entity->get($name, $locale);
				}
			}
			elseif($entity->getDefinition()->property($name)->get('type') == 'entity') {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name) as $entity)
						$res[$name][] = $entity->toArrayRawI18N($locales, $depth-1);
				}
				else
					$res[$name] = $entity->toArrayRawI18N($locales, $depth-1);
			}
			elseif($entity->getDefinition()->property($name)->get('many'))
				$res[$name] = $entity->get($name)->all();
			else
				$res[$name] = $entity->get($name);
		}

		return $res;
	}
526035
public function getYaml($messages, $locale)
    {
        $entities = $this->denormaliseMessages($messages);
        $content = $this->getDumper()->dump([
            $locale => $entities
        ], 99);
        return $content;
    }
153800
protected function getDatabaseTranslations(Locale $locale)
    {
        $messages   = [];
        $collection = $this->repository->getCollection();
        
        $collection->map(function (Dictionary $dictionary) use ($locale, &$messages) {
            $messages[$dictionary->getIdentifier()] = $dictionary->translate($locale->getCode())->getValue();
        });
        
        return $messages;
    }
801971
public function getObjectAclEntriesAsArray($entity)
    {
        $result = array();
        foreach ($this->getObjectAclEntries($entity) as $aclEntry) {
            $result[] = new AclEntry($aclEntry->getSecurityIdentity());
        }
        return $result;
    }
1177689
private function initializeFieldDescriptors($locale)
    {
        $this->fieldDescriptors['id'] = new DoctrineFieldDescriptor(
            'id',
            'id',
            static::$orderEntityName,
            'public.id',
            array(),
            true,
            false,
            'string'
        );
        $this->fieldDescriptors['number'] = new DoctrineFieldDescriptor(
            'number',
            'number',
            static::$orderEntityName,
            'salesorder.orders.number',
            array(),
            false,
            true,
            'string'
        );

        // TODO: get customer from order-address

        $contactJoin = array(
            static::$orderAddressEntityName => new DoctrineJoinDescriptor(
                static::$orderAddressEntityName,
                static::$orderEntityName . '.invoiceAddress'
            )
        );

        $this->fieldDescriptors['account'] = new DoctrineConcatenationFieldDescriptor(
            array(
                new DoctrineFieldDescriptor(
                    'accountName',
                    'account',
                    static::$orderAddressEntityName,
                    'contact.contacts.contact',
                    $contactJoin
                )
            ),
            'account',
            'salesorder.orders.account',
            ' ',
            false,
            false,
            'string',
            '',
            '160px'
        );

        $this->fieldDescriptors['contact'] = new DoctrineConcatenationFieldDescriptor(
            array(
                new DoctrineFieldDescriptor(
                    'firstName',
                    'contact',
                    static::$orderAddressEntityName,
                    'contact.contacts.contact',
                    $contactJoin
                ),
                new DoctrineFieldDescriptor(
                    'lastName',
                    'contact',
                    static::$orderAddressEntityName,
                    'contact.contacts.contact',
                    $contactJoin
                )
            ),
            'contact',
            'salesorder.orders.contact',
            ' ',
            false,
            false,
            'string',
            '',
            '160px',
            false
        );

        $this->fieldDescriptors['status'] = new DoctrineFieldDescriptor(
            'name',
            'status',
            static::$orderStatusTranslationEntityName,
            'salesorder.orders.status',
            array(
                static::$orderStatusEntityName => new DoctrineJoinDescriptor(
                    static::$orderStatusEntityName,
                    static::$orderEntityName . '.status'
                ),
                static::$orderStatusTranslationEntityName => new DoctrineJoinDescriptor(
                    static::$orderStatusTranslationEntityName,
                    static::$orderStatusEntityName . '.translations',
                    static::$orderStatusTranslationEntityName . ".locale = '" . $locale . "'"
                )
            ),
            false,
            false,
            'string'
        );

        $this->fieldDescriptors['type'] = new DoctrineFieldDescriptor(
            'name',
            'type',
            static::$orderTypeTranslationEntityName,
            'salesorder.orders.type',
            array(
                static::$orderTypeEntityName => new DoctrineJoinDescriptor(
                    static::$orderTypeEntityName,
                    static::$orderEntityName . '.type'
                ),
                static::$orderTypeTranslationEntityName => new DoctrineJoinDescriptor(
                    static::$orderTypeTranslationEntityName,
                    static::$orderTypeEntityName . '.translations',
                    static::$orderTypeTranslationEntityName . ".locale = '" . $locale . "'"
                )
            ),
            false,
            false,
            'string'
        );

        $this->fieldDescriptors['created'] = new DoctrineFieldDescriptor(
            'created',
            'created',
            static::$orderEntityName,
            'public.created',
            array(),
            false,
            false,
            'date'
        );

        $contactJoin = array(
            self::$contactEntityName => new DoctrineJoinDescriptor(
                self::$contactEntityName,
                self::$orderEntityName . '.responsibleContact'
            )
        );

        $this->fieldDescriptors['responsibleContact'] = new DoctrineConcatenationFieldDescriptor(
            array(
                new DoctrineFieldDescriptor(
                    'firstName',
                    'contact',
                    self::$contactEntityName,
                    'contact.contacts.contact',
                    $contactJoin
                ),
                new DoctrineFieldDescriptor(
                    'lastName',
                    'contact',
                    self::$contactEntityName,
                    'contact.contacts.contact',
                    $contactJoin
                )
            ),
            'responsibleContact',
            'salescore.responsible-contact',
            ' ',
            false,
            false,
            'string',
            '',
            '160px',
            false
        );
    }
185849
public function locale($locale, $menus)
    {
        $this->stack[] = [
            'locale' => $locale,
        ];

        $this->loadMenus($menus);

        $this->menus[] = array_pop($this->stack);
    }
470851
public function findMetaTag($key, $locale = null)
    {
        $criteria = array('keyword' => $key);
        if ($locale && property_exists($this->entityClass, 'locale')) {
            $criteria['locale'] = $locale;
        }

        return $this->getRepository()->findOneBy($criteria);
    }
1355253
private function addThumbnails($entities, $locale)
    {
        $ids = array_filter(array_column($entities, 'thumbnails'));
        $thumbnails = $this->getMediaManager()->getFormatUrls($ids, $locale);
        foreach ($entities as $key => $entity) {
            if (array_key_exists('thumbnails', $entity)
                && $entity['thumbnails']
                && array_key_exists($entity['thumbnails'], $thumbnails)
            ) {
                $entities[$key]['thumbnails'] = $thumbnails[$entity['thumbnails']];
            }
        }

        return $entities;
    }
777796
public function filter(array $locales)
    {
        $this->filtered = [];

        foreach ($locales as $locale) {
            $this->filterLocale($locale);
        }

        return $this->filtered;
    }
869734
protected function generateFields(Entity $entity)
    {
        $fields     = [];
        $descriptor = $entity->getDescriptor();
        $extensions = $descriptor->getExtensionList() ?: [];

        foreach ($extensions as $field) {
            $fields[] = $this->generateExtensionField($entity, $field);
        }

        return $fields;
    }
1297937
public function retrieveFieldDescriptors($locale)
    {
        $fieldDescriptors = [];

        $fieldDescriptors['id'] = new DoctrineFieldDescriptor(
            'id',
            'id',
            static::$attributeEntityName,
            null,
            [
                static::$attributeEntityName => new DoctrineJoinDescriptor(
                    static::$attributeEntityName,
                    static::$productEntityName . '.variantAttributes'
                ),
            ],
            true,
            false,
            'integer'
        );

        $fieldDescriptors['name'] = new DoctrineFieldDescriptor(
            'name',
            'name',
            static::$attributeTranslationEntityName,
            null,
            [
                static::$attributeEntityName => new DoctrineJoinDescriptor(
                    static::$attributeEntityName,
                    static::$productEntityName . '.variantAttributes'
                ),
                static::$attributeTranslationEntityName => new DoctrineJoinDescriptor(
                    static::$attributeTranslationEntityName,
                    static::$attributeEntityName . '.translations',
                    static::$attributeTranslationEntityName . '.locale = \'' . $locale . '\'',
                    DoctrineJoinDescriptor::JOIN_METHOD_INNER
                ),
            ],
            false,
            true,
            'string'
        );

        return $fieldDescriptors;
    }
105644
protected function buildLocalKey($entity, array $pairs)
    {
        $keys = array_keys($pairs);

        return $this->buildKey($entity, array_combine($keys, $keys));
    }
1360211
public function locales(array $locales = null)
    {
        return is_null($locales)
            ? $this->locales
            : ($this->locales = $locales);
    }
1137842
public function translate($object, $locale)
    {
        $classStack = $this->getNamespacesFromClass(get_class($object));

        foreach ($classStack as $classNamespace) {
            if (!array_key_exists($classNamespace, $this->configuration)) {
                continue;
            }

            $configuration = $this->configuration[$classNamespace];
            $idGetter = $configuration['idGetter'];
            $entityId = $object->$idGetter();

            foreach ($configuration['fields'] as $fieldName => $fieldConfiguration) {
                $setter = $fieldConfiguration['setter'];
                $translation = $this
                    ->entityTranslationProvider
                    ->getTranslation(
                        $configuration['alias'],
                        $entityId,
                        $fieldName,
                        $locale
                    );

                if ($translation || !$this->fallback) {
                    $object->$setter($translation);
                }
            }
        }

        return $object;
    }
1251288
public static function arrayToJSONI18N(array $entities, array $locales=[], $depth=0) {
		foreach($entities as $k=>$entity)
			$entities[$k] = $entity->toArrayI18N($locales, $depth);
		return json_encode($entities);
	}