/**
  * 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));
 }
 /**
  * @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);
 }
예제 #3
0
 /**
  * @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);
 }
 /**
  * @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;
         }
     }
 }
예제 #5
0
 /**
  * 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()));
     }
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function getCatalogue($locale = null)
 {
     return $this->translator->getCatalogue($locale);
 }
예제 #7
0
 /**
  * Returns the message catalogue
  *
  * @param string $locale
  *
  * @return MessageCatalogueInterface
  */
 protected function getCatalogue(string $locale) : MessageCatalogueInterface
 {
     return $this->translator->getCatalogue($locale);
 }
 /**
  * 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);
 }