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


PHP MessageCatalogue::getDomains方法代码示例

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


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

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

示例4: getAllTranslations

 private function getAllTranslations($locale)
 {
     $catalogue = new MessageCatalogue();
     $loader = $this->get('jms_translation.loader_manager');
     // load external resources, so current translations can be reused in the final translation
     foreach ($this->retrieveDirs() as $resource) {
         $catalogue->merge($loader->loadFromDirectory($resource, $locale));
     }
     $localesArray = array();
     foreach ($catalogue->getDomains() as $domain => $collection) {
         foreach ($collection->all() as $key => $translation) {
             $localesArray[$key] = $translation->getLocaleString();
         }
     }
     return $localesArray;
 }
开发者ID:carakas,项目名称:Framework,代码行数:16,代码来源:DefaultController.php

示例5: merge

 /**
  * @param MessageCatalogue $catalogue
  */
 public function merge(MessageCatalogue $catalogue)
 {
     foreach ($catalogue->getDomains() as $name => $domainCatalogue) {
         $this->getOrCreateDomain($name)->merge($domainCatalogue);
     }
 }
开发者ID:GabLeRoux,项目名称:JMSTranslationBundle,代码行数:9,代码来源:MessageCatalogue.php

示例6: testMerge

 public function testMerge()
 {
     $cat = new MessageCatalogue();
     $cat->add(new Message('foo', 'foo'));
     $cat2 = new MessageCatalogue();
     $cat2->add(new Message('foo', 'bar'));
     $cat->merge($cat2);
     $this->assertEquals(array('foo', 'bar'), array_keys($domains = $cat->getDomains()));
     $this->assertEquals(array('bar'), array_keys($cat2->getDomains()));
     $this->assertEquals(array('foo'), array_keys($domains['foo']->all()));
     $this->assertEquals(array('foo'), array_keys($domains['bar']->all()));
 }
开发者ID:pixel-cookers,项目名称:JMSTranslationBundle,代码行数:12,代码来源:MessageCatalogueTest.php


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