diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index d8d27301f04df..a4efdd15438b3 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -14,6 +14,8 @@ use Symfony\Component\Config\ConfigCacheFactory; use Symfony\Component\Config\ConfigCacheFactoryInterface; use Symfony\Component\Config\ConfigCacheInterface; +use Symfony\Component\Config\Resource\DirectoryResource; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Translation\Exception\InvalidArgumentException; use Symfony\Component\Translation\Exception\LogicException; use Symfony\Component\Translation\Exception\NotFoundResourceException; @@ -333,6 +335,10 @@ private function dumpCatalogue($locale, ConfigCacheInterface $cache): void $fallbackContent ); + foreach ($this->getDirectoryResources($locale) as $dir) { + $this->catalogues[$locale]->addResource($dir); + } + $cache->write($content, $this->catalogues[$locale]->getResources()); } @@ -463,4 +469,34 @@ private function getConfigCacheFactory(): ConfigCacheFactoryInterface return $this->configCacheFactory; } + + /** + * Fetches a unique list of directories where files were found + * for a catalogue. + * + * @param string $locale + * + * @return DirectoryResource[]|array + */ + private function getDirectoryResources($locale): array + { + $directories = array(); + foreach ($this->catalogues[$locale]->getResources() as $resource) { + if (!$resource instanceof FileResource) { + continue; + } + + $directory = \dirname($resource->getResource()); + if (!\in_array($directory, $directories, true)) { + $directories[] = $directory; + } + } + + return \array_map( + function ($directory) { + return new DirectoryResource($directory); + }, + $directories + ); + } }