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


PHP MessageCatalogue::getMetadata方法代码示例

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


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

示例1: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale));
     $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $targetElement = $dom->createElement('target');
         $metadata = $messages->getMetadata($source, $domain);
         if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
             foreach ($metadata['target-attributes'] as $name => $value) {
                 $targetElement->setAttribute($name, $value);
             }
         }
         $t = $translation->appendChild($targetElement);
         $t->appendChild($text);
         if ($this->hasMetadataArrayInfo('notes', $metadata)) {
             foreach ($metadata['notes'] as $note) {
                 if (!isset($note['content'])) {
                     continue;
                 }
                 $n = $translation->appendChild($dom->createElement('note'));
                 $n->appendChild($dom->createTextNode($note['content']));
                 if (isset($note['priority'])) {
                     $n->setAttribute('priority', $note['priority']);
                 }
                 if (isset($note['from'])) {
                     $n->setAttribute('from', $note['from']);
                 }
             }
         }
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:Nakard,项目名称:symfony,代码行数:52,代码来源:XliffFileDumper.php

示例2: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale));
     $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         $t = $translation->appendChild($dom->createElement('target'));
         $t->appendChild($dom->createTextNode($target));
         $metadata = $messages->getMetadata($source, $domain);
         if (null !== $metadata && array_key_exists('notes', $metadata) && is_array($metadata['notes'])) {
             foreach ($metadata['notes'] as $note) {
                 if (!isset($note['content'])) {
                     continue;
                 }
                 $n = $translation->appendChild($dom->createElement('note'));
                 $n->appendChild($dom->createTextNode($note['content']));
                 if (isset($note['priority'])) {
                     $n->setAttribute('priority', $note['priority']);
                 }
                 if (isset($note['from'])) {
                     $n->setAttribute('from', $note['from']);
                 }
             }
         }
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:alexbogo,项目名称:symfony,代码行数:44,代码来源:XliffFileDumper.php

示例3: dumpXliff2

 private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0');
     $xliff->setAttribute('version', '2.0');
     $xliff->setAttribute('srcLang', str_replace('_', '-', $defaultLocale));
     $xliff->setAttribute('trgLang', str_replace('_', '-', $messages->getLocale()));
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('id', $domain . '.' . $messages->getLocale());
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('unit');
         $translation->setAttribute('id', md5($source));
         $segment = $translation->appendChild($dom->createElement('segment'));
         $s = $segment->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $targetElement = $dom->createElement('target');
         $metadata = $messages->getMetadata($source, $domain);
         if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
             foreach ($metadata['target-attributes'] as $name => $value) {
                 $targetElement->setAttribute($name, $value);
             }
         }
         $t = $segment->appendChild($targetElement);
         $t->appendChild($text);
         $xliffFile->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:nakashu,项目名称:symfony,代码行数:32,代码来源:XliffFileDumper.php

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

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


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