当前位置: 首页>>代码示例>>PHP>>正文


PHP MessageCatalogue::addResource方法代码示例

本文整理汇总了PHP中Symfony\Component\Translation\MessageCatalogue::addResource方法的典型用法代码示例。如果您正苦于以下问题:PHP MessageCatalogue::addResource方法的具体用法?PHP MessageCatalogue::addResource怎么用?PHP MessageCatalogue::addResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Translation\MessageCatalogue的用法示例。


在下文中一共展示了MessageCatalogue::addResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * {@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;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:37,代码来源:QtFileLoader.php

示例2: load

 /**
  * {@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;
 }
开发者ID:peintune,项目名称:Ternado,代码行数:39,代码来源:XliffFileLoader.php

示例3: load

 /**
  * {@inheritdoc}
  */
 function load($resource, $locale, $domain = 'messages')
 {
     $catalogue = new MessageCatalogue($locale);
     $catalogue->addMessages(require $resource, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:netixpro,项目名称:symfony,代码行数:10,代码来源:PhpFileLoader.php

示例4: load

 /**
  *
  * {@inheritdoc}
  *
  */
 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 (!is_dir($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $rb = new \ResourceBundle($locale, $resource);
     } catch (\Exception $e) {
         // HHVM compatibility: constructor throws on invalid resource
         $rb = null;
     }
     if (!$rb) {
         throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
     } elseif (intl_is_failure($rb->getErrorCode())) {
         throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
     }
     $messages = $this->flatten($rb);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     if (class_exists('Symfony\\Component\\Config\\Resource\\DirectoryResource')) {
         $catalogue->addResource(new DirectoryResource($resource));
     }
     return $catalogue;
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:32,代码来源:IcuResFileLoader.php

示例5: load

 /**
  * {@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;
 }
开发者ID:symstriker,项目名称:symfony,代码行数:40,代码来源:XliffFileLoader.php

示例6: load

 /**
  * {@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;
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:35,代码来源:QtFileLoader.php

示例7: testLoadOldFormat

 public function testLoadOldFormat()
 {
     $expected = new MessageCatalogue('en');
     $expected->add(array('foo1' => 'bar', 'foo2' => 'bar', 'foo3' => 'bar', 'foo4' => 'bar'));
     $file = __DIR__ . '/xliff/old_format.xml';
     $expected->addResource(new FileResource($file));
     $this->assertEquals($expected, $this->getLoader()->load($file, 'en'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:8,代码来源:XliffLoaderTest.php

示例8: testLoadWithMetadata

 public function testLoadWithMetadata()
 {
     $expected = new MessageCatalogue('en');
     $expected->add(array('foo' => 'bar'));
     $file = $this->getInputFile('with_metadata');
     $expected->addResource(new FileResource($file));
     $this->assertEquals($expected, $this->load($file));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:8,代码来源:BaseLoaderTest.php

示例9: load

 /**
  * {@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;
 }
开发者ID:noelg,项目名称:symfony-demo,代码行数:14,代码来源:XliffFileLoader.php

示例10: load

 /**
  * {@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;
 }
开发者ID:alebon,项目名称:graviton,代码行数:20,代码来源:DoctrineODMLoader.php

示例11: load

    /**
     * {@inheritdoc}
     */
    public function load($resource, $locale, $domain = 'messages')
    {
        $rb = new \ResourceBundle($locale, $resource);

        if (!$rb) {
            throw new \RuntimeException("cannot load this resource : $resource");
        } elseif (intl_is_failure($rb->getErrorCode())) {
            throw new \RuntimeException($rb->getErrorMessage(), $rb->getErrorCode());
        }

        $messages = $this->flatten($rb);
        $catalogue = new MessageCatalogue($locale);
        $catalogue->add($messages, $domain);

        if (is_dir($resource)) {
            $catalogue->addResource(new DirectoryResource($resource));
        } elseif (is_file($resource.'.dat')) {
            $catalogue->addResource(new FileResource($resource.'.dat'));
        }

        return $catalogue;
    }
开发者ID:usefulthink,项目名称:symfony,代码行数:25,代码来源:ResourceBundleLoader.php

示例12: load

 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));
     }
     $messages = (require $resource);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:astronom,项目名称:TranslationBundle,代码行数:14,代码来源:Loader.php

示例13: load

 /**
  * {@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;
 }
开发者ID:ncud,项目名称:sagalaya,代码行数:19,代码来源:XliffFileLoader.php

示例14: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $previous = libxml_use_internal_errors(true);
     if (false === ($xml = simplexml_load_file($resource))) {
         libxml_use_internal_errors($previous);
         $error = libxml_get_last_error();
         throw new RuntimeException(sprintf('An error occurred while reading "%s": %s', $resource, $error->message));
     }
     libxml_use_internal_errors($previous);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $catalogue = new MessageCatalogue($locale);
     foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
         $id = ($resName = (string) $translation->attributes()->resname) ? $resName : (string) $translation->source;
         $catalogue->set($id, (string) $translation->target, $domain);
     }
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:21,代码来源:XliffLoader.php

示例15: load

 /**
  * {@inheritdoc}
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource . '.dat')) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource . '.dat')) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $rb = new \ResourceBundle($locale, $resource);
     if (!$rb) {
         throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
     } elseif (intl_is_failure($rb->getErrorCode())) {
         throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
     }
     $messages = $this->flatten($rb);
     $catalogue = new MessageCatalogue($locale);
     $catalogue->add($messages, $domain);
     $catalogue->addResource(new FileResource($resource . '.dat'));
     return $catalogue;
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:23,代码来源:IcuDatFileLoader.php


注:本文中的Symfony\Component\Translation\MessageCatalogue::addResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。