/** * @param Translator $translator * @param MessageCatalogueInterface[] $availableCatalogues * @param string $locale * @throws InvalidArgumentException * @return MessageCatalogueInterface|NULL */ public function compile(Translator $translator, array &$availableCatalogues, $locale) { if (empty($locale)) { throw new InvalidArgumentException("Invalid locale."); } if (isset($availableCatalogues[$locale])) { return $availableCatalogues; } $cacheKey = array($locale, $translator->getFallbackLocales()); $storage = $this->cache->getStorage(); if (!$storage instanceof Kdyby\Translation\Caching\PhpFileStorage) { if (($messages = $this->cache->load($cacheKey)) !== NULL) { $availableCatalogues[$locale] = new MessageCatalogue($locale, $messages); return $availableCatalogues; } $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); $this->cache->save($cacheKey, $availableCatalogues[$locale]->all()); return $availableCatalogues; } $storage->hint = $locale; $cached = $compiled = $this->cache->load($cacheKey); if ($compiled === NULL) { $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale); $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale)); $cached = $this->cache->load($cacheKey); } $availableCatalogues[$locale] = self::load($cached['file']); return $availableCatalogues; }
protected function execute(InputInterface $input, OutputInterface $output) { if ($this->validate($input, $output) !== TRUE) { return 1; } $this->extractor->addExtractor('php', new PhpExtractor()); $defaultLocale = null; foreach ($this->translator->getFallbackLocales() as $locale) { if (is_null($defaultLocale)) { $defaultLocale = $locale; } $catalogue = new MessageCatalogue($locale); $output->writeln(sprintf('<info>Locale %s</info>', $locale)); foreach ($this->scanDirs as $dir) { $output->writeln(sprintf('<info>Extracting %s</info>', $dir)); $this->extractor->extract($dir, $catalogue); } } $this->writer->writeTranslations($catalogue, $this->outputFormat, ['path' => $this->outputDir]); $output->writeln(''); $output->writeln(sprintf('<info>Catalogue was written to %s</info>', $this->outputDir)); $output->writeln(''); $output->writeln(sprintf('<info>Zapisuji do DB</info>')); $toTranslate = (include dirname(__FILE__) . '/../../../../../temp/lang/messages.' . $defaultLocale . '.php'); $texts = array(''); foreach ($toTranslate as $translate) { $texts[] = $translate; $trans = $this->translates->where('text', $translate)->fetch(); if (!$trans) { $this->translates->insert(array('text' => $translate)); } } $this->translates->where('NOT text', $texts)->delete(); $language = $this->languages->where('translate_locale', $defaultLocale)->fetch(); $catalogue = new MessageCatalogue($language['translate_locale']); foreach ($this->translates->getAll() as $translate) { $translatesLocale = $translate->related('translate_locale')->where('language_id', $language['id'])->fetch(); if ($translatesLocale) { $catalogue->set($translate['text'], $translatesLocale['translate']); } else { $catalogue->set($translate['text'], $translate['text']); } } $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->langDir]); return 0; }