當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。