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


PHP TranslatorInterface::getCatalogue方法代码示例

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


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

示例1: tryTranslate

 /**
  * Will check the translator for the key "eav.family.{$code}.label"
  * and humanize the code if no translation is found
  *
  * @param string|array $tIds
  * @param array        $parameters
  * @param string       $fallback
  * @param bool         $humanizeFallback
  * @return string
  */
 protected function tryTranslate($tIds, array $parameters = [], $fallback = null, $humanizeFallback = true)
 {
     if (!is_array($tIds)) {
         $tIds = [$tIds];
     }
     foreach ($tIds as $tId) {
         try {
             if ($this->translator instanceof TranslatorBagInterface) {
                 if ($this->translator->getCatalogue()->has($tId)) {
                     /** @noinspection PhpUndefinedMethodInspection */
                     return $this->translator->trans($tId, $parameters);
                 }
             } elseif ($this->translator instanceof TranslatorInterface) {
                 $label = $this->translator->trans($tId, $parameters);
                 if ($label !== $tId) {
                     return $label;
                 }
             }
         } catch (\InvalidArgumentException $e) {
             // Do nothing
         }
     }
     if ($fallback === null) {
         return null;
     }
     if (!$humanizeFallback) {
         return $fallback;
     }
     $pattern = '/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]|\\d{1,}/';
     return str_replace('_', ' ', preg_replace($pattern, ' $0', $fallback));
 }
开发者ID:VincentChalnot,项目名称:SidusEAVModelBundle,代码行数:41,代码来源:TranslatableTrait.php

示例2: transchoiceWithDefault

 /**
  * @param string $message
  * @param string $defaultMessage
  * @param int $count
  * @param array $arguments
  * @param null|string $domain
  * @param null|string $locale
  * @return string
  */
 public function transchoiceWithDefault($message, $defaultMessage, $count, array $arguments = array(), $domain = null, $locale = null)
 {
     if (null === $domain) {
         $domain = 'messages';
     }
     // If < sf2.6
     if (!method_exists($this->translator, 'getCatalogue')) {
         return $this->transchoiceWithDefaultLegacy($message, $defaultMessage, $count, $arguments, $domain, $locale);
     }
     if (false == $this->translator->getCatalogue($locale)->defines($message, $domain)) {
         return $this->translator->transChoice($defaultMessage, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
     }
     return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
 }
开发者ID:clytemnestra,项目名称:JMSTranslationBundle,代码行数:23,代码来源:TranslationExtension.php

示例3: collectMessage

 /**
  * @param string|null $locale
  * @param string|null $domain
  * @param string      $id
  * @param string      $translation
  * @param array|null  $parameters
  * @param int|null    $number
  */
 private function collectMessage($locale, $domain, $id, $translation, $parameters = array(), $number = null)
 {
     if (null === $domain) {
         $domain = 'messages';
     }
     $id = (string) $id;
     $catalogue = $this->translator->getCatalogue($locale);
     $locale = $catalogue->getLocale();
     if ($catalogue->defines($id, $domain)) {
         $state = self::MESSAGE_DEFINED;
     } elseif ($catalogue->has($id, $domain)) {
         $state = self::MESSAGE_EQUALS_FALLBACK;
         $fallbackCatalogue = $catalogue->getFallbackCatalogue();
         while ($fallbackCatalogue) {
             if ($fallbackCatalogue->defines($id, $domain)) {
                 $locale = $fallbackCatalogue->getLocale();
                 break;
             }
             $fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
         }
     } else {
         $state = self::MESSAGE_MISSING;
     }
     $this->messages[] = array('locale' => $locale, 'domain' => $domain, 'id' => $id, 'translation' => $translation, 'parameters' => $parameters, 'transChoiceNumber' => $number, 'state' => $state);
 }
开发者ID:yceruto,项目名称:symfony,代码行数:33,代码来源:DataCollectorTranslator.php

示例4: getUiLocale

 /**
  * @param \OAuth2\Endpoint\Authorization\AuthorizationInterface $authorization
  *
  * @return null|string
  */
 private function getUiLocale(AuthorizationInterface $authorization)
 {
     if (!method_exists($this->translator, 'getCatalogue') || !$authorization->hasQueryParam('ui_locales')) {
         return;
     }
     $ui_locales = explode(' ', $authorization->getQueryParam('ui_locales'));
     foreach ($ui_locales as $ui_locale) {
         $catalogue = $this->translator->getCatalogue($ui_locale);
         if (in_array('SpomkyLabsOAuth2Server', $catalogue->getDomains())) {
             return $ui_locale;
         }
     }
 }
开发者ID:spomky-labs,项目名称:oauth2-server-bundle,代码行数:18,代码来源:AuthorizationEndpointController.php

示例5: log

 /**
  * Logs for missing translations.
  *
  * @param string      $id
  * @param string|null $domain
  * @param string|null $locale
  */
 private function log($id, $domain, $locale)
 {
     if (null === $domain) {
         $domain = 'messages';
     }
     $id = (string) $id;
     $catalogue = $this->translator->getCatalogue($locale);
     if ($catalogue->defines($id, $domain)) {
         return;
     }
     if ($catalogue->has($id, $domain)) {
         $this->logger->debug('Translation use fallback catalogue.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale()));
     } else {
         $this->logger->warning('Translation not found.', array('id' => $id, 'domain' => $domain, 'locale' => $catalogue->getLocale()));
     }
 }
开发者ID:shegun-babs,项目名称:dakrush,代码行数:23,代码来源:LoggingTranslator.php

示例6: getCatalogue

 /**
  * {@inheritdoc}
  */
 public function getCatalogue($locale = null)
 {
     return $this->translator->getCatalogue($locale);
 }
开发者ID:gabiudrescu,项目名称:Sylius,代码行数:7,代码来源:ThemeAwareTranslator.php

示例7: getCatalogue

 /**
  * Returns the message catalogue
  *
  * @param string $locale
  *
  * @return MessageCatalogueInterface
  */
 protected function getCatalogue(string $locale) : MessageCatalogueInterface
 {
     return $this->translator->getCatalogue($locale);
 }
开发者ID:WellCommerce,项目名称:CoreBundle,代码行数:11,代码来源:TranslatorHelper.php

示例8: getProgress

 /**
  * Return the number of translated messages
  *
  * @param string $locale
  *
  * @return int
  */
 protected function getProgress($locale)
 {
     $catalogue = $this->translator->getCatalogue($locale);
     return count($catalogue->all(), COUNT_RECURSIVE);
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:12,代码来源:UiLocaleProvider.php


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