/**
  * {@inheritDoc}
  */
 public function validate(TranslatorBagInterface $translator, array $locales)
 {
     $allKeys = [];
     $byLocale = [];
     $missing = [];
     /* Read all messages from all domains from all locales and create array
      * of message IDs and array of IDs grouped by locales */
     foreach ($locales as $locale) {
         $localeMessages = $translator->getCatalogue($locale)->all();
         foreach ($localeMessages as $domain => $messages) {
             foreach ($messages as $id => $message) {
                 $key = "{$domain}.{$id}";
                 $byLocale[$locale][$key] = TRUE;
                 $allKeys[$key] = TRUE;
             }
         }
     }
     /* Compare IDs of each locale with union of all keys and build array of
      * missing IDs */
     foreach ($locales as $locale) {
         foreach (array_keys($allKeys) as $id) {
             if (!isset($byLocale[$locale][$id])) {
                 $missing[$locale][] = $id;
             }
         }
     }
     return $missing;
 }
Exemple #2
0
 function it_adds_custom_message(SessionInterface $session, TranslatorBagInterface $translator, MessageCatalogueInterface $messageCatalogue, FlashBagInterface $flashBag, MetadataInterface $metadata, RequestConfiguration $requestConfiguration, ResourceInterface $resource)
 {
     $metadata->getApplicationName()->willReturn('app');
     $metadata->getHumanizedName()->willReturn('book');
     $requestConfiguration->getMetadata()->willReturn($metadata);
     $requestConfiguration->getFlashMessage('send')->willReturn('app.book.send');
     $translator->getCatalogue('en')->willReturn($messageCatalogue);
     $messageCatalogue->has('app.book.send', 'flashes')->willReturn(true);
     $session->getBag('flashes')->willReturn($flashBag);
     $flashBag->add('success', 'app.book.send')->shouldBeCalled();
     $this->addSuccessFlash($requestConfiguration, 'send', $resource);
 }
 /**
  * @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);
 }
 /**
  * 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()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     if ($this->translator instanceof WarmableInterface) {
         $this->translator->warmUp($cacheDir);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getCatalogue($locale = null)
 {
     return $this->translator->getCatalogue($locale);
 }
 function it_proxies_getting_catalogue_for_given_locale_to_the_decorated_translator(TranslatorBagInterface $translator, MessageCatalogueInterface $messageCatalogue)
 {
     $translator->getCatalogue('pl_PL')->willReturn($messageCatalogue);
     $this->getCatalogue('pl_PL')->shouldReturn($messageCatalogue);
 }
 /**
  * Returns the message catalogue
  *
  * @param string $locale
  *
  * @return MessageCatalogueInterface
  */
 protected function getCatalogue(string $locale) : MessageCatalogueInterface
 {
     return $this->translator->getCatalogue($locale);
 }
Exemple #9
0
 /**
  * @param string $message
  * @param string $locale
  *
  * @return bool
  */
 private function isTranslationDefined($message, $locale)
 {
     $defaultCatalogue = $this->translator->getCatalogue($locale);
     return $defaultCatalogue->has($message, 'flashes');
 }