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


PHP MessageCatalogue::setMetadata方法代码示例

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


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

示例1: testDump

 public function testDump()
 {
     $catalogue = new MessageCatalogue('en_US');
     $catalogue->add(array('foo' => 'bar', 'key' => '', 'key.with.cdata' => '<source> & <target>'));
     $catalogue->setMetadata('foo', array('notes' => array(array('priority' => 1, 'from' => 'bar', 'content' => 'baz'))));
     $catalogue->setMetadata('key', array('notes' => array(array('content' => 'baz'), array('content' => 'qux'))));
     $tempDir = sys_get_temp_dir();
     $dumper = new XliffFileDumper();
     $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR'));
     $this->assertEquals(file_get_contents(__DIR__ . '/../fixtures/resources-clean.xlf'), file_get_contents($tempDir . '/messages.en_US.xlf'));
     unlink($tempDir . '/messages.en_US.xlf');
 }
开发者ID:scrobot,项目名称:Lumen,代码行数:12,代码来源:XliffFileDumperTest.php

示例2: testGetResultWithMetadata

 public function testGetResultWithMetadata()
 {
     $leftCatalogue = new MessageCatalogue('en', array('messages' => array('a' => 'old_a', 'b' => 'old_b')));
     $leftCatalogue->setMetadata('a', 'foo', 'messages');
     $leftCatalogue->setMetadata('b', 'bar', 'messages');
     $rightCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'new_b', 'c' => 'new_c')));
     $rightCatalogue->setMetadata('b', 'baz', 'messages');
     $rightCatalogue->setMetadata('c', 'qux', 'messages');
     $diffCatalogue = new MessageCatalogue('en', array('messages' => array('b' => 'old_b', 'c' => 'new_c')));
     $diffCatalogue->setMetadata('b', 'bar', 'messages');
     $diffCatalogue->setMetadata('c', 'qux', 'messages');
     $this->assertEquals($diffCatalogue, $this->createOperation($leftCatalogue, $rightCatalogue)->getResult());
 }
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:13,代码来源:DiffOperationTest.php

示例3: 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

示例4: load

 /**
  * Load translations and metadata of the trans-unit.
  *
  * {@inheritdoc}
  *
  * @api
  */
 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;
 }
开发者ID:migros,项目名称:LiipTranslationBundle,代码行数:33,代码来源:XliffFileLoader.php

示例5: testTargetAttributesMetadataIsSetInFile

    public function testTargetAttributesMetadataIsSetInFile()
    {
        $catalogue = new MessageCatalogue('en_US');
        $catalogue->add(array('foo' => 'bar'));
        $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
        $tempDir = sys_get_temp_dir();
        $dumper = new XliffFileDumper();
        $dumper->dump($catalogue, array('path' => $tempDir, 'default_locale' => 'fr_FR'));
        $content = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
  <file source-language="fr-FR" target-language="en-US" datatype="plaintext" original="file.ext">
    <body>
      <trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
        <source>foo</source>
        <target state="needs-translation">bar</target>
      </trans-unit>
    </body>
  </file>
</xliff>

EOT;
        $this->assertEquals($content, file_get_contents($tempDir . '/messages.en_US.xlf'));
        unlink($tempDir . '/messages.en_US.xlf');
    }
开发者ID:Nakard,项目名称:symfony,代码行数:25,代码来源:XliffFileDumperTest.php

示例6: testFormatCatalogueWithTargetAttributesMetadata

 public function testFormatCatalogueWithTargetAttributesMetadata()
 {
     $catalogue = new MessageCatalogue('en_US');
     $catalogue->add(array('foo' => 'bar'));
     $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
     $dumper = new XliffFileDumper();
     $this->assertStringEqualsFile(__DIR__ . '/../fixtures/resources-target-attributes.xlf', $dumper->formatCatalogue($catalogue, 'messages', array('default_locale' => 'fr_FR')));
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:8,代码来源:XliffFileDumperTest.php

示例7: testDumpWithTargetAttributesMetadata

 public function testDumpWithTargetAttributesMetadata()
 {
     $catalogue = new MessageCatalogue('en_US');
     $catalogue->add(array('foo' => 'bar'));
     $catalogue->setMetadata('foo', array('target-attributes' => array('state' => 'needs-translation')));
     $this->tempDir = sys_get_temp_dir();
     $dumper = new XliffFileDumper();
     $dumper->dump($catalogue, array('path' => $this->tempDir, 'default_locale' => 'fr_FR'));
     $this->assertEquals(file_get_contents(__DIR__ . '/../fixtures/resources-target-attributes.xlf'), file_get_contents($this->tempDir . '/messages.en_US.xlf'));
     unlink($this->tempDir . '/messages.en_US.xlf');
 }
开发者ID:nakashu,项目名称:symfony,代码行数:11,代码来源:XliffFileDumperTest.php

示例8: 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;
         // 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) $translation->target, $encoding);
         $catalogue->set((string) $source, $target, $domain);
         if (isset($translation->note)) {
             $notes = array();
             foreach ($translation->note as $xmlNote) {
                 $noteAttributes = $xmlNote->attributes();
                 $note = array('content' => $this->utf8ToCharset((string) $xmlNote, $encoding));
                 if (isset($noteAttributes['priority'])) {
                     $note['priority'] = (int) $noteAttributes['priority'];
                 }
                 if (isset($noteAttributes['from'])) {
                     $note['from'] = (string) $noteAttributes['from'];
                 }
                 $notes[] = $note;
             }
             $catalogue->setMetadata((string) $source, array('notes' => $notes), $domain);
         }
     }
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:brennantom,项目名称:hackazon,代码行数:45,代码来源:XliffFileLoader.php

示例9: testMetadataMerge

 public function testMetadataMerge()
 {
     $cat1 = new MessageCatalogue('en');
     $cat1->setMetadata('a', 'b');
     $this->assertEquals(array('messages' => array('a' => 'b')), $cat1->getMetadata('', ''), 'Cat1 contains messages metadata.');
     $cat2 = new MessageCatalogue('en');
     $cat2->setMetadata('b', 'c', 'domain');
     $this->assertEquals(array('domain' => array('b' => 'c')), $cat2->getMetadata('', ''), 'Cat2 contains domain metadata.');
     $cat1->addCatalogue($cat2);
     $this->assertEquals(array('messages' => array('a' => 'b'), 'domain' => array('b' => 'c')), $cat1->getMetadata('', ''), 'Cat1 contains merged metadata.');
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:11,代码来源:MessageCatalogueTest.php

示例10: filterCatalogue

 private function filterCatalogue(MessageCatalogue $catalogue, $domain)
 {
     $filteredCatalogue = new MessageCatalogue($catalogue->getLocale());
     if ($messages = $catalogue->all($domain)) {
         $filteredCatalogue->add($messages, $domain);
     }
     foreach ($catalogue->getResources() as $resource) {
         $filteredCatalogue->addResource($resource);
     }
     if ($metadata = $catalogue->getMetadata('', $domain)) {
         foreach ($metadata as $k => $v) {
             $filteredCatalogue->setMetadata($k, $v, $domain);
         }
     }
     return $filteredCatalogue;
 }
开发者ID:yceruto,项目名称:symfony,代码行数:16,代码来源:TranslationUpdateCommand.php

示例11: extractXliff2

 /**
  * @param \DOMDocument     $dom
  * @param MessageCatalogue $catalogue
  * @param string           $domain
  */
 private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
 {
     $xml = simplexml_import_dom($dom);
     $encoding = strtoupper($dom->encoding);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
     foreach ($xml->xpath('//xliff:unit/xliff:segment') as $segment) {
         $source = $segment->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($segment->target) ? $segment->target : $source), $encoding);
         $catalogue->set((string) $source, $target, $domain);
         $metadata = array();
         if (isset($segment->target) && $segment->target->attributes()) {
             $metadata['target-attributes'] = array();
             foreach ($segment->target->attributes() as $key => $value) {
                 $metadata['target-attributes'][$key] = (string) $value;
             }
         }
         $catalogue->setMetadata((string) $source, $metadata, $domain);
     }
 }
开发者ID:ayoah,项目名称:symfony,代码行数:26,代码来源:XliffFileLoader.php


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