Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\Translation\Reader; Chris@14: Chris@14: use Symfony\Component\Finder\Finder; Chris@14: use Symfony\Component\Translation\Loader\LoaderInterface; Chris@14: use Symfony\Component\Translation\MessageCatalogue; Chris@14: Chris@14: /** Chris@14: * TranslationReader reads translation messages from translation files. Chris@14: * Chris@14: * @author Michel Salib Chris@14: */ Chris@14: class TranslationReader implements TranslationReaderInterface Chris@14: { Chris@14: /** Chris@14: * Loaders used for import. Chris@14: * Chris@14: * @var array Chris@14: */ Chris@17: private $loaders = []; Chris@14: Chris@14: /** Chris@14: * Adds a loader to the translation extractor. Chris@14: * Chris@14: * @param string $format The format of the loader Chris@14: * @param LoaderInterface $loader Chris@14: */ Chris@14: public function addLoader($format, LoaderInterface $loader) Chris@14: { Chris@14: $this->loaders[$format] = $loader; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function read($directory, MessageCatalogue $catalogue) Chris@14: { Chris@14: if (!is_dir($directory)) { Chris@14: return; Chris@14: } Chris@14: Chris@14: foreach ($this->loaders as $format => $loader) { Chris@14: // load any existing translation files Chris@14: $finder = new Finder(); Chris@14: $extension = $catalogue->getLocale().'.'.$format; Chris@14: $files = $finder->files()->name('*.'.$extension)->in($directory); Chris@14: foreach ($files as $file) { Chris@17: $domain = substr($file->getFilename(), 0, -1 * \strlen($extension) - 1); Chris@14: $catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain)); Chris@14: } Chris@14: } Chris@14: } Chris@14: }