Import document by locale into given webspace.

@param array $parsedData
@param string $locale
@param string $format

@return bool
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;
    }
783182
public function load($locale)
    {
        if (isset($this->cache[$locale])) {
            return $this->cache[$locale];
        }

        // New Translator array
        $trans = [];
        // Split the language: language, region, locale, etc
        $parts = string_split($locale, '-');

        do {
            // Create a path for this set of parts
            $path = implode(DS, $parts);

            // Remove the last part
            if ($files = $this->findLanguageFile($path)) {
                $trans = $this->loadMessages($files, $trans);
            }

            array_pop($parts);
        } while ($parts);

        // Cache the Translator table locally
        return $this->cache[$locale] = $trans;
    }
261818
private function parseDates($data, $format)
    {
        foreach ($data as $key => $entry) {
            $data[$key]['date'] = $data[$key]['date']->format($format);
        }

        return $data;
    }
676534
private function importSingleTranslation($keyword, $text, $locale, $filename, $domain, $force = false)
    {
        if (strlen($keyword) > 255) {
            return false;
        }

        $translationGroup = $this->translationGroupManager->getTranslationGroupByKeywordAndDomain($keyword, $domain);

        if (!$translationGroup->hasTranslation($locale)) {
            $this->translationGroupManager->addTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        if (true === $force) {
            $this->translationGroupManager->updateTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        return false;
    }
1193115
public function create($data, $locale)
    {
        $mediaCollection = new Collection();

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

        if (array_key_exists('ids', $data)) {
            $medias = $this->mediaManager->getByIds($data['ids'], $locale);

            foreach ($medias as $media) {
                $mediaViewObject = new MediaViewObject();
                $mediaViewObject->setData($media);

                $mediaCollection[] = $mediaViewObject;
            }
        }

        return $mediaCollection;
    }
697210
public function load($data, $format = 'php')
    {
        if (!$data) {
            return $this;
        }

        if (\is_string($data) && \in_array($format, static::$formats, true)) {
            switch ($format) {
                case static::FORMAT_YML:
                    $this->loadYaml($data);
                    break;

                case static::FORMAT_JSON:
                    $this->loadJson($data);
                    break;

                case static::FORMAT_INI:
                    $this->loadIni($data);
                    break;

                case static::FORMAT_PHP:
                default:
                    $this->loadArray($data);
                    break;
            }

        } elseif (\is_array($data) || \is_object($data)) {
            $this->bindData($this->data, $data);
        }

        return $this;
    }
129335
protected function getFormatterDay($locale) {
		if (! isset($this->formattersDay[$locale])) {
			$this->formattersDay[$locale] = new IntlDateFormatter($locale, IntlDateFormatter::MEDIUM, IntlDateFormatter::NONE);
		}
		
		return $this->formattersDay[$locale];
	}
215752
public function import($locale, $filePath, OutputInterface $output = null, $format = '1.2.xliff')
    {
        $parsedDataList = $this->getParser($format)->parse($filePath, $locale);
        $failedImports = [];
        $importedCounter = 0;
        $successCounter = 0;

        if (null === $output) {
            $output = new NullOutput();
        }

        $progress = new ProgressBar($output, count($parsedDataList));
        $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%');
        $progress->start();

        foreach ($parsedDataList as $parsedData) {
            ++$importedCounter;

            if (!$this->importDocument($parsedData, $locale, $format)) {
                $failedImports[] = $parsedData;
            } else {
                ++$successCounter;
            }

            $this->logger->info(sprintf('Document %s/%s', $importedCounter, count($parsedDataList)));

            $progress->advance();
        }

        $progress->finish();

        $return = new \stdClass();
        $return->count = $importedCounter;
        $return->fails = count($failedImports);
        $return->successes = $successCounter;
        $return->failed = $failedImports;
        $return->exceptionStore = $this->exceptionStore;

        return $return;
    }
810375
public function supportsDenormalization($data, $type, $format = null)
    {
        return in_array($type, static::$classes) or in_array($type, static::$types)
           and is_string($data) and preg_match(static::REGEX, $data) > 0;
    }
137338
private function persistDocument($data, $document, $locale)
    {
        $formType = $this->getMetadataFactory()->getMetadataForAlias('article')->getFormType();
        $form = $this->createForm(
            $formType,
            $document,
            [
                // disable csrf protection, since we can't produce a token, because the form is cached on the client
                'csrf_protection' => false,
            ]
        );
        $form->submit($data, false);

        if (!$form->isValid()) {
            throw new InvalidFormException($form);
        }

        if (array_key_exists('author', $data) && null === $data['author']) {
            $document->setAuthor(null);
        }

        if (array_key_exists('additionalWebspaces', $data) && null === $data['additionalWebspaces']) {
            $document->setAdditionalWebspaces(null);
        }

        $this->getDocumentManager()->persist(
            $document,
            $locale,
            [
                'user' => $this->getUser()->getId(),
                'clear_missing_content' => false,
            ]
        );
    }
524242
protected function loadData($locale, $format)
	{
		if (!isset($this->dataCache[$locale][$format]))
		{
			
			$file = sprintf('%s/%s/language.'.$format, $this->dataDir, $locale);

			if (!is_file($file))
			{
				throw new \RuntimeException(sprintf('Unable to load the language data file "%s"', $file));
			}

			$this->dataCache[$locale][$format] = ($format == 'php') ? require $file : file_get_contents($file);
		}

		return $this->sortData($locale, $this->dataCache[$locale][$format]);
	}
871040
protected function setDocumentData($document, $locale, $format, $data)
    {
        $structure = $this->structureManager->getStructure($document->getStructureType(), Structure::TYPE_SNIPPET);
        $properties = $structure->getProperties(true);
        $node = $this->documentRegistry->getNodeForDocument($document);
        $node->setProperty(sprintf('i18n:%s-template', $locale), $document->getStructureType());
        $state = $this->getParser($format)->getPropertyData('state', $data, null, null, 2);
        $node->setProperty(sprintf('i18n:%s-state', $locale), $state);

        // Check title is set in xliff-file.
        if ('' === $this->getParser($format)->getPropertyData('title', $data)) {
            $this->addException(sprintf('Snippet(%s) has not set any title', $document->getUuid()), 'ignore');

            return false;
        }

        // Import document-property.
        foreach ($properties as $property) {
            $value = $this->getParser($format)->getPropertyData(
                $property->getName(),
                $data,
                $property->getContentTypeName()
            );

            $this->importProperty($property, $node, $structure, $value, null, $locale, $format);
        }

        return true;
    }
528019
public static function createFromString($locale, $format = self::UNDERSCORE)
    {
        $delimiter = '-';
        if (in_array($format, [self::UNDERSCORE, self::LCID])) {
            $delimiter = '_';
        }

        $parts = explode($delimiter, $locale);

        $localization = new self();
        $localization->setLanguage(strtolower($parts[0]));
        if (count($parts) > 1) {
            $localization->setCountry(strtolower($parts[1]));
        }

        return $localization;
    }
1215597
public function format($format, $language = 'en')
    {
        $this->format = $format;
        $this->language = $language;

        return $this;
    }
781153
protected function parseMigrationDefinitionData($data, MigrationDefinition $definition, $format = 'Yaml')
    {
        // basic validation

        /// @todo move to using the Validator component...

        $status = MigrationDefinition::STATUS_PARSED;

        if (!is_array($data)) {
            $status = MigrationDefinition::STATUS_INVALID;
            $message = "$format migration file '{$definition->path}' must contain an array as top element";
        } else {
            foreach ($data as $i => $stepDef) {
                if (!isset($stepDef['type']) || !is_string($stepDef['type'])) {
                    $status = MigrationDefinition::STATUS_INVALID;
                    $message = "$format migration file '{$definition->path}' misses or has a non-string 'type' element in step $i";
                    break;
                }
            }
        }

        if ($status != MigrationDefinition::STATUS_PARSED)
        {
            return new MigrationDefinition(
                $definition->name,
                $definition->path,
                $definition->rawDefinition,
                $status,
                array(),
                $message
            );
        }

        $stepDefs = array();
        foreach ($data as $stepDef) {
            $type = $stepDef['type'];
            unset($stepDef['type']);
            $stepDefs[] = new MigrationStep($type, $stepDef, array('path' => $definition->path));
        }

        return new MigrationDefinition(
            $definition->name,
            $definition->path,
            $definition->rawDefinition,
            MigrationDefinition::STATUS_PARSED,
            $stepDefs
        );
    }
434923
public static function fromLocale(string $locale): LocaleFormatter
    {
        $formatter = new NumberFormatter((string) $locale, NumberFormatter::CURRENCY);

        return new self($formatter);
    }
836867
protected function importProperty(
        PropertyInterface $property,
        NodeInterface $node,
        StructureInterface $structure,
        $value,
        $webspaceKey,
        $locale,
        $format
    ) {
        $contentType = $property->getContentTypeName();

        if (!$this->importManager->hasImport($contentType, $format)) {
            return;
        }

        $translateProperty = $this->legacyPropertyFactory->createTranslatedProperty($property, $locale, $structure);
        $this->importManager->import($contentType, $node, $translateProperty, $value, null, $webspaceKey, $locale);
    }