public function submitFormTranslate(Form $form) { $values = $form->getValues(); //existuje preklad ? $translatesLocale = $this->row->related('translate_locale')->where('language_id', $this->webLanguage)->fetch(); if ($translatesLocale) { if ($values['translate'] != '') { $translatesLocale->update(array('translate' => $values['translate'])); } else { $translatesLocale->delete(); } } else { $this->row->related('translate_locale')->insert(array('translate' => $values['translate'], 'language_id' => $this->webLanguage)); } $language = $this->languages->get($this->webLanguage); $catalogue = new MessageCatalogue($language['translate_locale']); foreach ($this->model->getAll() as $translate) { $translatesLocale = $translate->related('translate_locale')->where('language_id', $this->webLanguage)->fetch(); if ($translatesLocale) { $catalogue->set($translate['text'], $translatesLocale['translate']); } else { $catalogue->set($translate['text'], $translate['text']); } } $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->context->parameters['appDir'] . '/lang/']); $this->flashMessage($this->translator->trans('translate.translated')); $this->redirect('this'); }
/** * Extracts translation messages from a file to the catalogue. * * @param string $file The path to look into * @param MessageCatalogue $catalogue The catalogue */ public function extractFile($file, MessageCatalogue $catalogue) { $buffer = NULL; $parser = new Parser(); $parser->shortNoEscape = TRUE; foreach ($tokens = $parser->parse(file_get_contents($file)) as $token) { if ($token->type !== $token::MACRO_TAG || !in_array($token->name, array('_', '/_'), TRUE)) { if ($buffer !== NULL) { $buffer .= $token->text; } continue; } if ($token->name === '/_') { $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $buffer, $buffer); $buffer = NULL; } elseif ($token->name === '_' && empty($token->value)) { $buffer = ''; } else { $args = new MacroTokens($token->value); $writer = new PhpWriter($args, $token->modifiers); $message = $writer->write('%node.word'); if (in_array(substr(trim($message), 0, 1), array('"', '\''), TRUE)) { $message = substr(trim($message), 1, -1); } $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $message, $message); } } }
public function load($resource = null, $culture = null, $version = 0) { $resourceName = $resource === null ? 'Global * Debug' : $resource . '/' . $culture; $cacheFile = $this->cacheDir . '/translations/resource-' . ($resource === null ? 'global' : $resource) . '-' . $culture . '-v' . $version . '.php'; if (!$this->cache || !file_exists($cacheFile) || filemtime($cacheFile) + self::TTL * 3600 < time()) { try { // Delete Symfony Catalogue $fs = new Filesystem(); $finder = new Finder(); $sfCacheFiles = $finder->in($this->cacheDir . '/translations/')->name('catalogue.' . $culture . '.*'); $fs->remove($sfCacheFiles); } catch (Exception $e) { } $catalogue = new MessageCatalogue($culture); if ($resource === null) { $nodesSql = 'SELECT N.node_name, N.node_type, A.attrib_name, A.attrib_original, NULL AS value_translation FROM translation_node N INNER JOIN translation_attribute A ON N.node_id = A.attrib_node'; $nodesStmt = $this->doctrine->getManager()->getConnection()->prepare($nodesSql); $nodesStmt->execute(); } else { $nodesSql = 'SELECT N.node_name, N.node_type, A.attrib_name, A.attrib_original, V.value_translation FROM translation_node N INNER JOIN translation_attribute A ON N.node_id=A.attrib_node LEFT JOIN translation_value V ON A.attrib_id = V.value_attribute AND (V.value_resource = :resource OR V.value_resource IS NULL)'; $nodesStmt = $this->doctrine->getManager()->getConnection()->prepare($nodesSql); $nodesStmt->execute(['resource' => $resource]); } $nodes = $nodesStmt->fetchAll(); foreach ($nodes as $node) { $id = $node['node_name'] . '.' . $node['attrib_name']; $value = $node['value_translation']; $type = $node['node_type']; if ($value != null) { $catalogue->set($id, $value, $type); } else { if ($resource != null) { if ($this->debug) { $this->logger->warning('Translation for key "' . $id . '" and region "' . $resourceName . '" not found!'); } } if ($this->debug) { $catalogue->set($id, '[--' . $node['attrib_original'] . '--]', $type); } else { $catalogue->set($id, $node['attrib_original'], $type); } } } // Save Cache $cacheContent = '<?php ' . PHP_EOL . 'use Symfony\\Component\\Translation\\MessageCatalogue; ' . PHP_EOL . '$catalogue = new MessageCatalogue(\'' . $culture . '\', ' . var_export($catalogue->all(), true) . '); ' . PHP_EOL . 'return $catalogue;'; if (!is_dir($this->cacheDir . '/translations')) { mkdir($this->cacheDir . '/translations'); } file_put_contents($cacheFile, $cacheContent); } else { $catalogue = (include $cacheFile); } return $catalogue; }
/** * Extracts translation messages from a file to the catalogue. * * @param string $file The path to look into * @param MessageCatalogue $catalogue The catalogue */ public function extractFile($file, MessageCatalogue $catalogue) { $pInfo = pathinfo($file); $tokens = token_get_all(file_get_contents($file)); $data = array(); foreach ($tokens as $c) { if (is_array($c)) { if ($c[0] != T_STRING && $c[0] != T_CONSTANT_ENCAPSED_STRING) { continue; } if ($c[0] == T_STRING && in_array($c[1], $this->keywords)) { $next = true; continue; } if ($c[0] == T_CONSTANT_ENCAPSED_STRING && $next == true) { $data[substr($c[1], 1, -1)][] = $pInfo['basename'] . ':' . $c[2]; $next = false; } } else { if ($c == ')') { $next = false; } } } foreach ($data as $d => $value) { $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $d, $d); } }
public function testGetSet() { $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar'))); $catalogue->set('foo1', 'foo1', 'domain1'); $this->assertEquals('foo', $catalogue->get('foo', 'domain1')); $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1')); }
/** * Loads a locale. * * @param mixed $resource A resource * @param string $locale A locale * @param string $domain The domain * * @return MessageCatalogue A MessageCatalogue instance * * @throws NotFoundResourceException when the resource cannot be found * @throws InvalidResourceException when the resource cannot be loaded */ public function load($resource, $locale, $domain = 'messages') { if ($this->loadAll !== true) { return new MessageCatalogue($locale); } $dql = <<<'DQL' SELECT t FROM MjrLibraryEntitiesBundle:System\Translation t WHERE t.Locale = :locale ORDER BY t.Id ASC DQL; $query = $this->entityManager->createQuery($dql); $query->setParameter(':locale', $locale); /** @var Translation[] $results */ $results = $query->getResult(); $catalogue = new MessageCatalogue($locale); if (count($results) > 0) { foreach ($results as $result) { $catalogue->set($result->getIdentity(), $result->getTranslation(), $domain); } } return $catalogue; }
/** * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $writer = $this->getContainer()->get('translation.writer'); if (!$this->checkParameters($input, $output, $writer)) { return 1; } // get bundle directory $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle')); $bundleTransPath = $foundBundle->getPath() . '/Resources/translations'; $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName())); // create catalogue $catalogue = new MessageCatalogue($input->getArgument('locale')); $output->writeln('Parsing templates'); $annotations = $this->getContainer()->get('oro_security.acl.annotation_provider')->getBundleAnnotations(array($foundBundle->getPath())); /** @var $annotation Acl*/ /** @var $annotations AclAnnotationStorage*/ foreach ($annotations->getAnnotations() as $annotation) { if ($label = $annotation->getLabel()) { $catalogue->set($label, $input->getOption('prefix') . $label); } } // load any existing messages from the translation files $output->writeln('Loading translation files'); $loader = $this->getContainer()->get('translation.loader'); $loader->loadMessages($bundleTransPath, $catalogue); // show compiled list of messages if ($input->getOption('dump-messages') === true) { $this->dumpMessages($input, $output, $catalogue); } // save the files if ($input->getOption('force') === true) { $this->saveMessages($input, $output, $catalogue, $writer, $bundleTransPath); } }
/** * Applies version to the supplied path. * * @param string $path A path * * @return string The versionized path */ public function applyVersion($path) { $file = $path; // apply the base path if ('/' !== substr($path, 0, 1)) { $file = '/' . $path; } $reved = $this->getRevedFilename($file); $absPath = $this->rootDir . $file; $absReved = $this->rootDir . $reved; // $reved or unversioned if (file_exists($absReved)) { return $reved; // look in filesystem } else { $pattern = preg_replace('/\\.([^\\.]+$)/', '.*.$1', $absPath); $regex = preg_replace('/\\.([^\\.]+$)/', '\\.[\\d\\w]{' . $this->hashLength . '}\\.$1', $absPath); $base = str_replace($path, '', $absPath); foreach (glob($pattern) as $filepath) { if (preg_match('#' . $regex . '#', $filepath, $match)) { $result = str_replace($base, '', $filepath); $this->summary->set($file, $result); return $filepath; } } } return $path; }
/** * Applies version to the supplied path. * * @param string $path A path * @param string|bool|null $version A specific version * * @return string The versionized path */ protected function applyVersion($path, $version = null) { $file = $path; // apply the base path if ('/' !== substr($path, 0, 1)) { $file = $this->basePath . $path; } $reved = $this->summary->get($file); $fullpath = $this->getRoot() . $file; $fullreved = $this->getRoot() . $reved; // $reved or unversioned if (file_exists($fullreved)) { return $reved; // fallback } else { $pattern = preg_replace('/\\.([^\\.]+$)/', '.*.$1', $fullpath); $regex = preg_replace('/\\.([^\\.]+$)/', '\\.[\\d\\w]{8}\\.$1', $fullpath); $base = str_replace($path, '', $fullpath); foreach (glob($pattern) as $filepath) { if (preg_match('#' . $regex . '#', $filepath)) { $result = str_replace($base, '', $filepath); $this->summary->set($file, $result); return $result; } } } return $path; }
/** * {@inheritdoc} * * @api */ public function load($resource, $locale, $domain = 'messages') { if (!stream_is_local($resource)) { throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); } if (!file_exists($resource)) { throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } list($xml, $encoding) = $this->parseFile($resource); $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2'); $catalogue = new MessageCatalogue($locale); foreach ($xml->xpath('//xliff:trans-unit') as $translation) { $attributes = $translation->attributes(); if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) { continue; } $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; $target = (string) $translation->target; // If the xlf file has another encoding specified, try to convert it because // simple_xml will always return utf-8 encoded values if ('UTF-8' !== $encoding && !empty($encoding)) { if (function_exists('mb_convert_encoding')) { $target = mb_convert_encoding($target, $encoding, 'UTF-8'); } elseif (function_exists('iconv')) { $target = iconv('UTF-8', $encoding, $target); } else { throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); } } $catalogue->set((string) $source, $target, $domain); } $catalogue->addResource(new FileResource($resource)); return $catalogue; }
/** * {@inheritdoc} * * @api */ public function load($resource, $locale, $domain = 'messages') { if (!stream_is_local($resource)) { throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); } if (!file_exists($resource)) { throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } try { $dom = XmlUtils::loadFile($resource); } catch (\InvalidArgumentException $e) { throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e); } $internalErrors = libxml_use_internal_errors(true); libxml_clear_errors(); $xpath = new \DOMXPath($dom); $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]'); $catalogue = new MessageCatalogue($locale); if ($nodes->length == 1) { $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message'); foreach ($translations as $translation) { $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue; if (!empty($translationValue)) { $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain); } $translation = $translation->nextSibling; } $catalogue->addResource(new FileResource($resource)); } libxml_use_internal_errors($internalErrors); return $catalogue; }
/** * {@inheritdoc} * * @api */ public function load($resource, $locale, $domain = 'messages') { if (!stream_is_local($resource)) { throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); } if (!file_exists($resource)) { throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } $dom = new \DOMDocument(); $current = libxml_use_internal_errors(true); if (!@$dom->load($resource, defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0)) { throw new InvalidResourceException(implode("\n", $this->getXmlErrors())); } $xpath = new \DOMXPath($dom); $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]'); $catalogue = new MessageCatalogue($locale); if ($nodes->length == 1) { $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message'); foreach ($translations as $translation) { $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue; if (!empty($translationValue)) { $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain); } $translation = $translation->nextSibling; } $catalogue->addResource(new FileResource($resource)); } libxml_use_internal_errors($current); return $catalogue; }
/** * {@inheritdoc} * * @api */ public function load($resource, $locale, $domain = 'messages') { if (!stream_is_local($resource)) { throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource)); } if (!file_exists($resource)) { throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource)); } list($xml, $encoding) = $this->parseFile($resource); $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2'); $catalogue = new MessageCatalogue($locale); foreach ($xml->xpath('//xliff:trans-unit') as $translation) { $attributes = $translation->attributes(); if (!(isset($attributes['resname']) || isset($translation->source))) { continue; } $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source; // If the xlf file has another encoding specified, try to convert it because // simple_xml will always return utf-8 encoded values $target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding); $catalogue->set((string) $source, $target, $domain); $metadata = array(); if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) { $metadata['notes'] = $notes; } if ($translation->target->attributes()) { $metadata['target-attributes'] = $translation->target->attributes(); } $catalogue->setMetadata((string) $source, $metadata, $domain); } if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) { $catalogue->addResource(new FileResource($resource)); } return $catalogue; }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { // get bundle directory $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle')); $bundleTransPath = $foundBundle->getPath() . '/Resources/translations'; $writer = $this->getContainer()->get('translation.writer'); $supportedFormats = $writer->getFormats(); if (!in_array($input->getOption('output-format'), $supportedFormats)) { $output->writeln('<error>Wrong output format</error>'); $output->writeln('Supported formats are ' . implode(', ', $supportedFormats) . '.'); return 1; } $this->orm = $this->getContainer()->get('doctrine.orm.default_entity_manager'); $languages = $this->orm->getRepository('RaindropTranslationBundle:Language')->findAll(); $tokens = $this->orm->getRepository('RaindropTranslationBundle:LanguageToken')->findAll(); foreach ($languages as $language) { $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $language, $foundBundle->getName())); // create catalogue $catalogue = new MessageCatalogue($language); foreach ($tokens as $token) { $translation = $this->orm->getRepository('RaindropTranslationBundle:LanguageTranslation')->findOneBy(array('language' => $language, 'languageToken' => $token, 'catalogue' => $token->getCatalogue())); if (!empty($translation)) { $content = $translation->getTranslation() != '' ? $translation->getTranslation() : null; $catalogue->set($token->getToken(), $content); } } $writer->writeTranslations($catalogue, $input->getOption('output-format'), array('path' => $bundleTransPath)); } }
protected function getCatalogue($locale, $messages) { $catalogue = new MessageCatalogue($locale); foreach ($messages as $key => $translation) { $catalogue->set($key, $translation); } return $catalogue; }
/** * Extract titles for translation * * @param string $directory * @param MessageCatalogue $catalogue * * @return MessageCatalogue */ public function extract($directory, MessageCatalogue $catalogue) { $routes = $this->getRoutesByBundleDir($directory); $titles = $this->titleService->getStoredTitlesRepository()->getTitles($routes); foreach ($titles as $titleRecord) { $catalogue->set($titleRecord['shortTitle'], $this->prefix . $titleRecord['shortTitle']); } return $catalogue; }
/** * Insére les traductions en base de donnée dans le catalogue * * @param $resource * @param $locale * @param string $domain * @return MessageCatalogue */ public function load($resource, $locale, $domain = 'messages') { $catalogue = new MessageCatalogue($locale); $wordings = $this->em->getRepository('TerTranslateBundle:Wording')->findAll(); foreach ($wordings as $trans) { $catalogue->set($trans->getCode(), $trans->translate($locale, false)->getValue(), $trans->getDomain()->getCode()); } return $catalogue; }
/** * Create a catalog and fills it in with messages * * @param string $locale * @param array $dictionary * @return MessageCatalogue */ public function getCatalogue($locale, $dictionary) { $catalogue = new MessageCatalogue($locale); foreach ($dictionary as $domain => $messages) { foreach ($messages as $key => $translation) { $catalogue->set($key, $translation, $domain); } } return $catalogue; }
public function load($resource, $locale, $domain = 'messages') { $language = $this->languageRepository->findByLocale($locale); $translations = $this->translationRepository->findByLanguage($language, $domain); $catalogue = new MessageCatalogue($locale); foreach ($translations as $translation) { $catalogue->set($translation->getLanguageToken()->getToken(), $translation->getTranslation(), $domain); } return $catalogue; }
protected function extractTemplate($template, MessageCatalogue $catalogue) { $visitor = $this->twig->getExtension('translator')->getTranslationNodeVisitor(); $visitor->enable(); $this->twig->parse($this->twig->tokenize($template)); foreach ($visitor->getMessages() as $message) { $catalogue->set(trim($message[0]), $this->prefix . trim($message[0]), $message[1] ? $message[1] : $this->defaultDomain); } $visitor->disable(); }
protected function extractTemplate($template, MessageCatalogue $catalogue) { $visitor = $this->twig->getExtension('Symfony\\Bridge\\Twig\\Extension\\TranslationExtension')->getTranslationNodeVisitor(); $visitor->enable(); $this->twig->parse($this->twig->tokenize(new \Twig_Source($template, ''))); foreach ($visitor->getMessages() as $message) { $catalogue->set(trim($message[0]), $this->prefix . trim($message[0]), $message[1] ?: $this->defaultDomain); } $visitor->disable(); }
/** * {@inheritdoc} */ public function load($resource, $locale, $domain = 'messages') { $xml = $this->parseFile($resource); $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2'); $catalogue = new MessageCatalogue($locale); foreach ($xml->xpath('//xliff:trans-unit') as $translation) { $catalogue->set((string) $translation->source, (string) $translation->target, $domain); } $catalogue->addResource(new FileResource($resource)); return $catalogue; }
/** * Loads a locale. * * @param mixed $resource A resource * @param string $locale A locale * @param string $domain The domain * * @return MessageCatalogue A MessageCatalogue instance * * @api * * @throws NotFoundResourceException when the resource cannot be found * @throws InvalidResourceException when the resource cannot be loaded */ public function load($resource, $locale, $domain = 'messages') { $query = $this->em->createQuery("SELECT Trn " . "FROM AppBundle:Translation\\Language Lng, AppBundle:Translation\\Message Msg, AppBundle:Translation\\Translation Trn " . "WHERE Lng.locale = :locale " . "AND Trn.language = Lng AND Trn.domain = :domain AND Trn.inCharge = true " . "AND Trn.message = Msg")->setParameter('locale', $locale)->setParameter('domain', $domain == 'messages' ? '' : $domain); $translations = $query->getResult(); $catalogue = new MessageCatalogue($locale); /** @var \AppBundle\Entity\Translation\Translation $translation */ foreach ($translations as $translation) { $catalogue->set($translation->getMessage()->getName(), $translation->getText(), $translation->getDomain() == '' ? 'messages' : $translation->getDomain()); } return $catalogue; }
public function load($resource, $locale, $domain = 'messages') { $catalogue = new MessageCatalogue($locale); if ($locale = $this->_entityManager->getRepository('W3buildTranslateBundle:Locale')->findByCode($locale)) { $translations = $locale->getTranslations(); foreach ($translations as $translation) { $catalogue->set($translation->getMsgId()->getMsgId(), $translation->getMsgStr()); } } return $catalogue; }
/** * {@inheritDoc} * * @param mixed $resource resource * @param string $locale locale name * @param string $domain message domain * * @return MessageCatalogue */ public function load($resource, $locale, $domain = 'messages') { $repository = $this->getRepository(); $messages = $repository->findBy(array('domain' => $domain, 'locale' => $locale, 'isLocalized' => true)); $catalogue = new MessageCatalogue($locale); array_walk($messages, function ($message) use($catalogue) { $catalogue->set((string) $message->getOriginal(), $message->getTranslated(), $message->getDomain()); }); $catalogue->addResource(new FileResource($resource)); return $catalogue; }
function load($resource, $locale, $domain = 'messages') { $cataloguesDB = $this->catalogueRepository->findAll(); $catalogue = new MessageCatalogue($locale); foreach ($cataloguesDB as $ctlg) { $translations = $this->translationRepository->getTranslations($locale, $ctlg->getName()); foreach ($translations as $token => $translation) { $catalogue->set($token, $translation, $ctlg->getName()); } } return $catalogue; }
public function load($resource, $locale, $domain = 'messages') { // Clear translation cache $this->clearLanguageCache($locale); $translations = $this->translationRepository->findBy(array('locale' => $locale)); /* @var $catalogue MessageCatalogue */ $catalogue = new MessageCatalogue($locale); /* @var $translation TokenTranslation */ foreach ($translations as $translation) { $catalogue->set($translation->getToken()->getToken(), $translation->getName(), $domain); } return $catalogue; }
/** * {@inheritdoc} */ public function load($resource, $locale, $domain = 'messages') { $catalogue = new MessageCatalogue($locale); $transUnits = $this->storage->getTransUnitsByLocaleAndDomain($locale, $domain); foreach ($transUnits as $transUnit) { foreach ($transUnit['translations'] as $translation) { if ($translation['locale'] == $locale) { $catalogue->set($transUnit['key'], $translation['content'], $domain); } } } return $catalogue; }
/** * @{@inheritdoc} */ public function load($resource, $locale, $domain = 'messages') { if (!isset($this->catalogues[$locale])) { $catalogue = new MessageCatalogue($locale); $translations = $this->translationRepository->findBy(array('locale' => $locale)); foreach ($translations as $translation) { $catalogue->set($translation->getKeyword(), $translation->getText(), $translation->getDomain()); } $this->catalogues[$locale] = $catalogue; } else { $catalogue = $this->catalogues[$locale]; } return $catalogue; }
/** * {@inheritdoc} * * @api */ public function load($resource, $locale, $domain = 'messages') { if (!stream_is_local($resource)) { throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource)); } $xml = $this->parseFile($resource); $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2'); $catalogue = new MessageCatalogue($locale); foreach ($xml->xpath('//xliff:trans-unit') as $translation) { $catalogue->set((string) $translation->source, (string) $translation->target, $domain); } $catalogue->addResource(new FileResource($resource)); return $catalogue; }