/** * @param string $locale * @param string $bundlePath * * @return MessageCatalogue */ protected function extractViewTranslationKeys($locale, $bundlePath) { $extractedCatalogue = new MessageCatalogue($locale); $bundleViewsPath = $bundlePath . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'; if ($this->filesystem->exists($bundleViewsPath)) { $this->extractor->extract($bundleViewsPath, $extractedCatalogue); } return $extractedCatalogue; }
/** * @param string $source * @param string $locale * * @return MessageCatalogueInterface | null */ public function extract($source, $locale) { if (!$this->isSourceAvailable($source)) { return; } $fs = new Filesystem(); /* @var Bundle $foundBundle */ $foundBundle = $this->kernel->getBundle($this->bundle); // load any messages from templates $extractedCatalogue = new MessageCatalogue($locale); $resourcesDir = $this->resolveResourcesDirectory($foundBundle); if ($fs->exists($resourcesDir)) { $this->extractor->extract($resourcesDir, $extractedCatalogue); } // load any existing messages from the translation files $translationsDir = $foundBundle->getPath() . '/Resources/translations'; if ($fs->exists($translationsDir)) { $currentCatalogue = new MessageCatalogue($locale); $this->loader->loadMessages($translationsDir, $currentCatalogue); foreach ($extractedCatalogue->getDomains() as $domain) { $messages = $currentCatalogue->all($domain); if (count($messages)) { $extractedCatalogue->add($messages, $domain); } } } return $extractedCatalogue; }