Пример #1
0
 public function dump()
 {
     $allMessages = [];
     $locales = $this->translator->getAvailableLocales();
     foreach ($locales as $locale) {
         $catalogue = $this->translator->getCatalogue($locale);
         $messages = $catalogue->all();
         $shortLocale = $this->getShortLocale($locale);
         $allMessages[$shortLocale] = $messages;
     }
     return Json::encode($allMessages, Json::PRETTY);
 }
 /**
  * Saves translation to catalog. ONLY NEON IS SUPPORTED AT THIS MOMENT
  *
  * @param string $locale
  * @param string $code
  * @param string $string
  */
 private function saveTranslationToCatalogue($locale, $code, $string)
 {
     if (!in_array($locale, $this->translator->getAvailableLocales())) {
         throw new Kdyby\TranslationControl\InvalidArgumentException(sprintf('Catalog "%s" is unknown.', $locale));
     }
     $catalog = $this->translator->getCatalogue($locale);
     $catalogFound = FALSE;
     foreach ($catalog->getResources() as $resource) {
         if (get_class($resource) != 'Symfony\\Component\\Config\\Resource\\FileResource') {
             continue;
         }
         /** @var \Symfony\Component\Config\Resource\FileResource $resource */
         $filePath = $resource->getResource();
         if (pathinfo($filePath, PATHINFO_EXTENSION) != 'neon' || !Nette\Utils\Strings::endsWith(strtolower($filePath), sprintf('%s.neon', strtolower($locale)))) {
             continue;
         }
         $catalog->add(array($code => $string));
         $this->saveTranslationToNeonFile($filePath, $code, $string);
         $catalogFound = TRUE;
     }
     if (!$catalogFound) {
         throw new Kdyby\TranslationControl\UnsupportedCatalogException('Only neon catalog is supported.');
     }
 }