當前位置: 首頁>>代碼示例>>PHP>>正文


PHP MessageCatalogue::has方法代碼示例

本文整理匯總了PHP中JMS\TranslationBundle\Model\MessageCatalogue::has方法的典型用法代碼示例。如果您正苦於以下問題:PHP MessageCatalogue::has方法的具體用法?PHP MessageCatalogue::has怎麽用?PHP MessageCatalogue::has使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在JMS\TranslationBundle\Model\MessageCatalogue的用法示例。


在下文中一共展示了MessageCatalogue::has方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: setConfig

 /**
  * @param Config $config
  */
 private function setConfig(Config $config)
 {
     $this->config = $config;
     $this->logger->info(sprintf("Loading catalogues from \"%s\"", $config->getTranslationsDir()));
     $this->existingCatalogue = new MessageCatalogue();
     // load external resources, so current translations can be reused in the final translation
     foreach ($config->getLoadResources() as $resource) {
         $this->existingCatalogue->merge($this->loader->loadFromDirectory($resource, $config->getLocale()));
     }
     $this->existingCatalogue->merge($this->loader->loadFromDirectory($config->getTranslationsDir(), $config->getLocale()));
     $this->extractor->reset();
     $this->extractor->setDirectories($config->getScanDirs());
     $this->extractor->setExcludedDirs($config->getExcludedDirs());
     $this->extractor->setExcludedNames($config->getExcludedNames());
     $this->extractor->setEnabledExtractors($config->getEnabledExtractors());
     $this->logger->info("Extracting translation keys");
     $this->scannedCatalogue = $this->extractor->extract();
     $this->scannedCatalogue->setLocale($config->getLocale());
     // merge existing messages into scanned messages
     foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
         foreach ($domainCatalogue->all() as $message) {
             if (!$this->existingCatalogue->has($message)) {
                 continue;
             }
             $existingMessage = clone $this->existingCatalogue->get($message->getId(), $message->getDomain());
             $existingMessage->mergeScanned($message);
             $this->scannedCatalogue->set($existingMessage, true);
         }
     }
     if ($this->config->isKeepOldMessages()) {
         foreach ($this->existingCatalogue->getDomains() as $domainCatalogue) {
             foreach ($domainCatalogue->all() as $message) {
                 if ($this->scannedCatalogue->has($message)) {
                     continue;
                 }
                 $this->scannedCatalogue->add($message);
             }
         }
     }
     //keep old translations translated
     if ($this->config->isKeepOldTranslationMessages()) {
         $locale = $this->scannedCatalogue->getLocale();
         /** @var MessageCatalogue $domainCatalogue */
         foreach ($this->scannedCatalogue->getDomains() as $domainCatalogue) {
             /** @var Message $message */
             foreach ($domainCatalogue->all() as $message) {
                 $translated = $this->translator->trans($message->getId(), array(), $message->getDomain(), $locale);
                 $message->setLocaleString($translated);
                 $message->setNew(false);
             }
         }
     }
 }
開發者ID:clytemnestra,項目名稱:JMSTranslationBundle,代碼行數:56,代碼來源:Updater.php


注:本文中的JMS\TranslationBundle\Model\MessageCatalogue::has方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。