Create a excerpt object by given data.

@param array $data
@param string $locale

@return ExcerptViewObject
764266
public function create($data, $locale)
    {
        $excerpt = new ExcerptViewObject();

        if (empty($data)) {
            return $excerpt;
        }

        $excerpt->title = $data['title'];
        $excerpt->more = $data['more'];
        $excerpt->description = $data['description'];
        $excerpt->tags = $this->tagCollectionFactory->create($data['tags']);
        $excerpt->categories = $this->categoryCollectionFactory->create($data['categories'], $locale);
        $excerpt->icon = $this->mediaCollectionFactory->create($data['icon'], $locale);
        $excerpt->images = $this->mediaCollectionFactory->create($data['images'], $locale);

        return $excerpt;
    }
970379
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);
            }
        }
    }
361659
public function load($resource, $locale, $domain = 'messages')
    {
        /* @var MessageCatalogue $catalogue */
        $base_catalogue = parent::load($resource, $locale, $domain);
        $catalogue = new MessageCatalogue($locale);
        $catalogue->addCatalogue($base_catalogue);

        // Process a second pass over the file to collect metadata
        $xml = simplexml_load_file($resource);
        $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
        foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
            // Read the attributes
            $attributes = (array) $translation->attributes();
            $attributes = $attributes['@attributes'];
            if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
                continue;
            }
            $key = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
            $metadata = (array) $attributes;

            // read the notes
            if (isset($translation->note)) {
                $metadata['note'] = (string) $translation->note;
            }

            $catalogue->setMetadata((string) $key, $metadata, $domain);
        }

        return $catalogue;
    }
486423
public function create($view = null, array $data = [])
    {
        if (is_null($view)) {
            return $this;
        }

        return $this->render($view, $data, true)->content();
    }
1348448
private function parseDocument(array $data)
    {
        $result = null;

        $dataSegment = $this->getArrayValue($data, DocumentInterface::KEYWORD_DATA, null);
        if (empty($dataSegment) === false && is_array($dataSegment) === true) {
            $isProbablySingle = $this->isProbablySingleIdentity($dataSegment);
            $parsed           = $isProbablySingle === true ?
                $this->parseSinglePrimaryData($dataSegment) :
                $this->parseArrayOfPrimaryData($dataSegment);

            if ($parsed !== null) {
                $result = new DocumentObject($parsed);
            }
        } elseif ($dataSegment !== null) {
            $this->errors->addDataError('Invalid element.');
        }

        return $result;
    }
825598
public function joinTranslations($locale)
    {
        $this->getInstance()
            ->innerJoin($this->mainAlias.'.translations', 'translation', Expr\Join::WITH, 'translation.locale = :locale')
            ->setParameter('locale', $locale);

        return $this;
    }
230089
public function setLocale($locale)
    {
        $this->locale = $locale;

        $this->getContentRoute()->setLocale($locale);

        return $this;
    }
1231354
protected function extractData(\DOMDocument $dom, $locale)
    {
        $xml = simplexml_import_dom($dom);
        $encoding = strtoupper($dom->encoding);
        $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');

        $documents = [];

        foreach ($xml->xpath('//xliff:file') as $file) {
            $fileAttributes = $file->attributes();

            if (!isset($fileAttributes['original'])) {
                continue;
            }

            $uuid = (string) $fileAttributes['original'];
            $data = $this->getData($file, $encoding);

            $template = null;

            if (isset($data['structureType'])) {
                $template = $data['structureType']['value'];
                unset($data['structureType']);
            }

            $documents[] = [
                'uuid' => $uuid,
                'locale' => $locale,
                'structureType' => $template,
                'data' => $data,
            ];
        }

        return $documents;
    }
1076412
protected function getTemplateDataForLocale($template,$locale) {
		// path to document with subjects
		$metafile = $this->templatespath.'/'.$locale.'/subjects.xml';
		
		if (!file_exists($metafile)) {
			// file with subjects not found
			return null;
		}
		
		// load and parse document with subjects
		$xml = @file_get_contents($metafile);
		
		if (!$xml || $xml == '') {
			return null;
		}
		
		$array = \LSS\XML2Array::createArray($xml);
		
		// our template is not found in this document so it is not there
		if (!isset($array['templates'][$template])) {
			return null;
		}
		
		$templatefile = $this->templatespath.'/'.$locale.'/'.$template.'.htm';
		
		// check if template file exists for this locale
		if (!file_exists($templatefile)) {
			return null;
		}
		
		$tmpl = ($locale != '') ? $locale.'/':'';
		
		$tmpl .= $template;
		
		// all was fine. return found template
		return array('subject'=>$array['templates'][$template]['subject'],
			'file'=>$tmpl);
	}
1344509
public function LocaleInformation($locale = null)
    {
        // Check locale and get object
        if ($locale) {
            $localeObj = Locale::getByLocale($locale);
        } else {
            $localeObj = Locale::getDefault();
        }
        $locale = $localeObj->getLocale();

        // Check linking mode
        $linkingMode = $this->getLinkingMode($locale);

        // Check link
        $link = $this->LocaleLink($locale);

        // Store basic locale information
        return ArrayData::create([
            'Locale' => $locale,
            'LocaleRFC1766' => i18n::convert_rfc1766($locale),
            'URLSegment' => $localeObj->getURLSegment(),
            'Title' => $localeObj->getTitle(),
            'LanguageNative' => $localeObj->getNativeName(),
            'Language' => i18n::getData()->langFromLocale($locale),
            'Link' => $link,
            'AbsoluteLink' => $link ? Director::absoluteURL($link) : null,
            'LinkingMode' => $linkingMode
        ]);
    }
1006623
protected function getTranslationOrNew($locale)
    {
        if (($translation = $this->getTranslation($locale)) === null) {
            $translation = $this->createNewTranslation($locale);
        }

        return $translation;
    }
548298
protected function importDocument(array $parsedData, $locale, $format)
    {
        try {
            $uuid = $parsedData['uuid'];
            $data = $parsedData['data'];
            $documentType = Structure::TYPE_SNIPPET;

            /** @var SnippetDocument $document */
            $document = $this->documentManager->find(
                $uuid,
                $locale,
                [
                    'type' => $documentType,
                    'load_ghost_content' => false,
                ]
            );

            if (!$document instanceof SnippetDocument) {
                throw new \Exception(
                    sprintf('Document(%s) is not an instanecof SnippetDocument', $uuid)
                );
            }

            if (!$this->setDocumentData($document, $locale, $format, $data)) {
                return false;
            }

            // set required data
            $document->setTitle($this->getParser($format)->getPropertyData('title', $data));

            // save document
            $this->documentManager->persist($document, $locale);
            $this->documentManager->publish($document, $locale);
            $this->documentManager->flush();
            $this->documentRegistry->clear(); // FIXME else it failed on multiple page import

            return true;
        } catch (\Exception $e) {
            if ($e instanceof DocumentManagerException) {
                return false;
            }

            $this->logger->error(
                sprintf(
                    '<info>%s</info>%s: <error>%s</error>%s',
                    $uuid,
                    PHP_EOL . get_class($e),
                    $e->getMessage(),
                    PHP_EOL . $e->getTraceAsString()
                )
            );

            $this->documentManager->flush();
            $this->documentManager->clear();
        }

        return false;
    }
308103
public function initWriter( $locale )
    {
        $this->dom = $this->openTranslationFileForWriting( $locale );
        $this->writeLocale = $locale;
    }
1069418
public function findByLocale(string $locale): ICollection
	{
		$builder = $this->builder()
			->innerJoin('_pages', '[_locales]', 'l', '_pages.localeId = l.id')
			->andWhere('[url] IS NOT NULL')
			->andWhere('[visible] = %i', 1)
			->andWhere('[l.name] = %s', $locale);
		return $this->toCollection($builder);
	}
28473
public function make($view, array $data = [])
    {
        $location = $this->finder->find($view);

        if ( ! $location) {
            throw new \Exception(sprintf('View `%s` cannot be found!', $view));
        }

        return new View($location, $view, $data);
    }
826027
public static function createFromArray(array $data)
    {
        $self = new self();

        if (isset($data['id'])) {
            $self->setId($data['id']);
        }
        if (isset($data['type'])) {
            $self->setType($data['type']);
        }
        if (isset($data['translated'])) {
            $self->setTranslated($data['translated']);
        }
        if (isset($data['flagged'])) {
            $self->setFlagged($data['flagged']);
        }
        if (isset($data['status'])) {
            $self->setStatus($data['status']);
        }
        if (isset($data['translation'])) {
            $self->setTranslation($data['translation']);
        }
        if (isset($data['revision'])) {
            $self->setRevision($data['revision']);
        }
        if (isset($data['comments'])) {
            $self->setComments($data['comments']);
        }
        if (isset($data['modified'])) {
            $self->setModified($data['modified']);
        }
        if (isset($data['author'])) {
            $self->setAuthor($data['author']);
        }
        if (isset($data['flagger'])) {
            $self->setFlagger($data['flagger']);
        }
        if (isset($data['locale'])) {
            $self->setLocale($data['locale']);
        }
        if (isset($data['plurals'])) {
            $self->setPlurals($data['plurals']);
        }

        return $self;
    }
1235323
protected function getCatalogContent($locale, $domain) {
		$path = $this->getCatalogPath($locale, $domain);
		
		if (! is_file($path)) {
			return false;
		}
		
		if (! is_readable($path)) {
			throw new ReadError('Catalog file: "' . $path . '" exists but can\'t be read');
		}
		
		$result = file_get_contents($path);
		
		if ($result === false) {
			throw new ReadError('Error has occurred while reading the file: "' . $path . '"');
		}
		
		$this->lastFilePath = $path;
		
		return $result;
	}