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


PHP Model\MessageCatalogue类代码示例

本文整理汇总了PHP中JMS\TranslationBundle\Model\MessageCatalogue的典型用法代码示例。如果您正苦于以下问题:PHP MessageCatalogue类的具体用法?PHP MessageCatalogue怎么用?PHP MessageCatalogue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: write

 public function write(MessageCatalogue $catalogue, $domain, $filePath, $format)
 {
     $newCatalogue = new MessageCatalogue();
     $newCatalogue->setLocale($catalogue->getLocale());
     foreach (array_keys($catalogue->getDomains()) as $catalogueDomainString) {
         if ($catalogue->getLocale() !== 'en' && $this->hasEnglishCatalogue($filePath)) {
             $englishCatalogue = $this->loadEnglishCatalogue($filePath, $domain, $format);
         }
         $domainMessageCollection = $catalogue->getDomain($catalogueDomainString);
         /** @var Message $message */
         foreach ($domainMessageCollection->all() as $message) {
             if ($message->getDomain() !== $domain) {
                 continue;
             }
             $newMessage = $this->makeXliffMessage($message);
             if ($message->getId() === $message->getSourceString()) {
                 if (isset($englishCatalogue)) {
                     try {
                         $newMessage->setDesc($englishCatalogue->get($message->getId(), $message->getDomain())->getLocaleString());
                     } catch (InvalidArgumentException $e) {
                         continue;
                     }
                 } else {
                     $newMessage->setDesc($message->getLocaleString());
                 }
             }
             $newCatalogue->add($newMessage);
         }
     }
     $this->innerFileWriter->write($newCatalogue, $domain, $filePath, $format);
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:31,代码来源:CatalogueMapperFileWriter.php

示例2: extract

 public function extract()
 {
     $catalogue = new MessageCatalogue();
     $collection = $this->router instanceof I18nRouter ? $this->router->getOriginalRouteCollection() : $this->router->getRouteCollection();
     foreach ($collection->all() as $name => $route) {
         if ($this->routeExclusionStrategy->shouldExcludeRoute($name, $route)) {
             continue;
         }
         ///////////////////////////////////////
         // Begin customizations
         $meaning = "Route Controller and method: " . $route->getDefault('_controller');
         // set a default value
         // prefix with zikula module url if requested
         if ($route->hasDefault('_zkModule')) {
             $zkNoBundlePrefix = $route->getOption('zkNoBundlePrefix');
             if (!isset($zkNoBundlePrefix) || !$zkNoBundlePrefix) {
                 $meaning = "This is a route from the " . $route->getDefault('_zkModule') . "Bundle and will include a translated prefix.";
             }
         }
         // End customizations
         ///////////////////////////////////////
         $message = new Message($name, $this->domain);
         $message->setDesc($route->getPath());
         if (isset($meaning)) {
             $message->setMeaning($meaning);
         }
         $catalogue->add($message);
     }
     return $catalogue;
 }
开发者ID:Silwereth,项目名称:core,代码行数:30,代码来源:ZikulaRouteTranslationExtractor.php

示例3: dump

 public function dump(MessageCatalogue $catalogue, $domain = 'messages', $filePath = null)
 {
     $structure = $catalogue->getDomain($domain)->all();
     if ($this->prettyPrint) {
         $tmpStructure = array();
         foreach ($structure as $id => $message) {
             $pointer =& $tmpStructure;
             $parts = explode('.', $id);
             // this algorithm only works if the messages are alphabetically
             // ordered, in particular it must be guaranteed that parent paths
             // are before sub-paths, e.g.
             // array_keys($structure) = array('foo.bar', 'foo.bar.baz')
             // but NOT: array_keys($structure) = array('foo.bar.baz', 'foo.bar')
             for ($i = 0, $c = count($parts); $i < $c; $i++) {
                 if ($i + 1 === $c) {
                     $pointer[$parts[$i]] = $message;
                     break;
                 }
                 if (!isset($pointer[$parts[$i]])) {
                     $pointer[$parts[$i]] = array();
                 }
                 if ($pointer[$parts[$i]] instanceof Message) {
                     $subPath = implode('.', array_slice($parts, $i));
                     $pointer[$subPath] = $message;
                     break;
                 }
                 $pointer =& $pointer[$parts[$i]];
             }
         }
         $structure = $tmpStructure;
         unset($tmpStructure);
     }
     return $this->dumpStructure($structure);
 }
开发者ID:Kofel,项目名称:JMSTranslationBundle,代码行数:34,代码来源:ArrayStructureDumper.php

示例4: compare

 /**
  * Compares two message catalogues.
  *
  * @param MessageCatalogue $current
  * @param MessageCatalogue $new
  * @return ChangeSet
  */
 public function compare(MessageCatalogue $current, MessageCatalogue $new)
 {
     $newMessages = array();
     foreach ($new->getDomains() as $name => $domain) {
         if ($this->domains && !isset($this->domains[$name])) {
             continue;
         }
         if (isset($this->ignoredDomains[$name])) {
             continue;
         }
         foreach ($domain->all() as $message) {
             if ($current->has($message)) {
                 // FIXME: Compare what has changed
                 continue;
             }
             $newMessages[] = $message;
         }
     }
     $deletedMessages = array();
     foreach ($current->getDomains() as $name => $domain) {
         if ($this->domains && !isset($this->domains[$name])) {
             continue;
         }
         if (isset($this->ignoredDomains[$name])) {
             continue;
         }
         foreach ($domain->all() as $message) {
             if ($new->has($message)) {
                 continue;
             }
             $deletedMessages[] = $message;
         }
     }
     return new ChangeSet($newMessages, $deletedMessages);
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:42,代码来源:CatalogueComparator.php

示例5: getTranslations

 /**
  * Get the translations
  *
  * @return MessageCatalogue
  */
 protected function getTranslations()
 {
     $catalogue = new MessageCatalogue();
     $labels = array();
     $entities = $this->getEntities();
     foreach ($entities as $entity) {
         $labels[] = $entity . '.label';
         $labels[] = $entity . '.show.title';
         $labels[] = $entity . '.edit.title';
         $labels[] = $entity . '.list.title';
         $labels[] = $entity . '.new.title';
         $labels[] = $entity . '.delete.title';
     }
     //avoid doublons
     $uniqueLabels = array_unique($labels);
     foreach ($uniqueLabels as $uniqueLabel) {
         $message = new Message($uniqueLabel, $this->domain);
         $catalogue->add($message);
     }
     if ($this->customizedFlash) {
         $flashLabels = $this->getFlashsLabels($entities);
         foreach ($flashLabels as $flashLabel) {
             $message = new Message($flashLabel, $this->domain);
             $catalogue->add($message);
         }
     }
     return $catalogue;
 }
开发者ID:A5sys,项目名称:EasyAdminPopupBundle,代码行数:33,代码来源:EntityExtractor.php

示例6: testCdataOutput

    public function testCdataOutput()
    {
        $dumper = $this->getDumper();
        $catalogue = new MessageCatalogue();
        $catalogue->add(Message::create('foo')->setLocaleString('<bar>')->setDesc('<baz>'));
        $expected = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
  <file source-language="en" target-language="" datatype="plaintext" original="not.available">
    <header>
      <tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
      <note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
    </header>
    <body>
      <trans-unit id="0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" resname="foo">
        <source><![CDATA[<baz>]]></source>
        <target state="new"><![CDATA[<bar>]]></target>
      </trans-unit>
    </body>
  </file>
</xliff>

EOF;
        $this->assertEquals($expected, $dumper->dump($catalogue, 'messages'));
    }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:25,代码来源:XliffDumperTest.php

示例7: testExtractConstraints

 public function testExtractConstraints()
 {
     $expected = new MessageCatalogue();
     $path = __DIR__ . '/Fixture/MyFormModel.php';
     $message = new Message('form.error.name_required', 'validators');
     $expected->add($message);
     $this->assertEquals($expected, $this->extract('MyFormModel.php'));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:8,代码来源:ValidationExtractorTest.php

示例8: extract

 public function extract()
 {
     $catalogue = new MessageCatalogue();
     foreach ($this->fieldTypeCollectionFactory->getConcreteFieldTypesIdentifiers() as $fieldTypeIdentifier) {
         $catalogue->add(new Message($fieldTypeIdentifier . '.name', 'fieldtypes'));
     }
     return $catalogue;
 }
开发者ID:ezsystems,项目名称:ezpublish-kernel,代码行数:8,代码来源:FieldTypesTranslationExtractor.php

示例9: load

 /**
  * @param mixed $resource
  * @param string $locale
  * @param string $domain
  * @return MessageCatalogue
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $previous = libxml_use_internal_errors(true);
     if (false === ($doc = simplexml_load_file($resource))) {
         libxml_use_internal_errors($previous);
         $libxmlError = libxml_get_last_error();
         throw new RuntimeException(sprintf('Could not load XML-file "%s": %s', $resource, $libxmlError->message));
     }
     libxml_use_internal_errors($previous);
     $doc->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $doc->registerXPathNamespace('jms', 'urn:jms:translation');
     $hasReferenceFiles = in_array('urn:jms:translation', $doc->getNamespaces(true));
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale($locale);
     /** @var \SimpleXMLElement $trans */
     foreach ($doc->xpath('//xliff:trans-unit') as $trans) {
         $id = ($resName = (string) $trans->attributes()->resname) ? $resName : (string) $trans->source;
         /** @var Message $m */
         $m = Message::create($id, $domain)->setDesc((string) $trans->source)->setLocaleString((string) $trans->target);
         $m->setApproved($trans['approved'] == 'yes');
         if (isset($trans->target['state'])) {
             $m->setState((string) $trans->target['state']);
         }
         // Create closure
         $addNoteToMessage = function (Message $m, $note) {
             $m->addNote((string) $note, isset($note['from']) ? (string) $note['from'] : null);
         };
         // If the translation has a note
         if (isset($trans->note)) {
             // If we have more than one note. We can't use is_array becuase $trans->note is a \SimpleXmlElement
             if (count($trans->note) > 1) {
                 foreach ($trans->note as $note) {
                     $addNoteToMessage($m, $note);
                 }
             } else {
                 $addNoteToMessage($m, $trans->note);
             }
         }
         $catalogue->add($m);
         if ($hasReferenceFiles) {
             foreach ($trans->xpath('./jms:reference-file') as $file) {
                 $line = (string) $file->attributes()->line;
                 $column = (string) $file->attributes()->column;
                 $m->addSource(new FileSource((string) $file, $line ? (int) $line : null, $column ? (int) $column : null));
             }
         }
         if ($meaning = (string) $trans->attributes()->extradata) {
             if (0 === strpos($meaning, 'Meaning: ')) {
                 $meaning = substr($meaning, 9);
             }
             $m->setMeaning($meaning);
         }
         if (!($state = (string) $trans->target->attributes()->state) || 'new' !== $state) {
             $m->setNew(false);
         }
     }
     return $catalogue;
 }
开发者ID:kazak,项目名称:forum,代码行数:64,代码来源:XliffLoader.php

示例10: load

 /**
  * Converts Symfony's message catalogue to the catalogue of this
  * bundle.
  *
  * @param mixed $resource
  * @param string $locale
  * @param string $domain
  * @return MessageCatalogue
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale($locale);
     foreach ($this->loader->load($resource, $locale, $domain)->all($domain) as $id => $message) {
         $catalogue->add(Message::create($id, $domain)->setLocaleString($message)->setNew(false));
     }
     return $catalogue;
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:18,代码来源:SymfonyLoaderAdapter.php

示例11: testDumpStructureWithoutPrettyPrint

 public function testDumpStructureWithoutPrettyPrint()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale('fr');
     $catalogue->add(new Message('foo.bar.baz'));
     $dumper = new PhpDumper();
     $dumper->setPrettyPrint(false);
     $this->assertEquals($this->getOutput('structure_wo_pretty_print'), $dumper->dump($catalogue, 'messages'));
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:9,代码来源:PhpDumperTest.php

示例12: extract

 public function extract()
 {
     $catalogue = new MessageCatalogue();
     foreach ($this->i18nLoader->extract($this->router->getRouteCollection()) as $name => $route) {
         $message = new Message($name, $this->domain);
         $message->setDesc($route->getPattern());
         $catalogue->add($message);
     }
     return $catalogue;
 }
开发者ID:natxet,项目名称:JMSI18nRoutingBundle,代码行数:10,代码来源:RouteTranslationExtractor.php

示例13: getStructureCatalogue

 /**
  * Get the catalogue used for the structure tests
  *
  * @return MessageCatalogue
  */
 protected function getStructureCatalogue()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale('en');
     $message = new Message('foo.bar.baz');
     $message->addSource(new FileSource('/a/b/c/foo/bar', 1, 2));
     $message->addSource(new FileSource('bar/baz', 1, 2));
     $catalogue->add($message);
     return $catalogue;
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:15,代码来源:XliffDumperTest.php

示例14: testPathWithSubPath

 public function testPathWithSubPath()
 {
     $catalogue = new MessageCatalogue();
     $catalogue->setLocale('fr');
     $catalogue->add(new Message('foo.bar'));
     $catalogue->add(new Message('foo.bar.baz'));
     $dumper = $this->getDumper();
     $dumper->expects($this->once())->method('dumpStructure')->with(array('foo' => array('bar' => new Message('foo.bar'), 'bar.baz' => new Message('foo.bar.baz'))))->will($this->returnValue('foo'));
     $this->assertEquals('foo', $dumper->dump($catalogue, 'messages'));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:10,代码来源:ArrayStructureDumperTest.php

示例15: write

 /**
  * @param \JMS\TranslationBundle\Model\MessageCatalogue $catalogue
  * @param string $domain
  * @param string $filePath
  * @param string $format
  * @throws \JMS\TranslationBundle\Exception\InvalidArgumentException
  */
 public function write(MessageCatalogue $catalogue, $domain, $filePath, $format)
 {
     if (!isset($this->dumpers[$format])) {
         throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $format));
     }
     // sort messages before dumping
     $catalogue->getDomain($domain)->sort(function ($a, $b) {
         return strcmp($a->getId(), $b->getId());
     });
     file_put_contents($filePath, $this->dumpers[$format]->dump($catalogue, $domain));
 }
开发者ID:smacp,项目名称:JMSTranslationBundle,代码行数:18,代码来源:FileWriter.php


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