diff --git a/Command/ImportTranslationsCommand.php b/Command/ImportTranslationsCommand.php index 9def8d06..aa1dd80b 100644 --- a/Command/ImportTranslationsCommand.php +++ b/Command/ImportTranslationsCommand.php @@ -199,7 +199,12 @@ protected function importComponentTranslationFiles(array $locales, array $domain */ protected function importAppTranslationFiles(array $locales, array $domains) { - $finder = $this->findTranslationsFiles($this->getApplication()->getKernel()->getRootDir(), $locales, $domains); + if (Kernel::MAJOR_VERSION >= 4) { + $translationPath = $this->getApplication()->getKernel()->getProjectDir().'/translations'; + $finder = $this->findTranslationsFiles($translationPath, $locales, $domains, false); + } else { + $finder = $this->findTranslationsFiles($this->getApplication()->getKernel()->getRootDir(), $locales, $domains); + } $this->importTranslationFiles($finder); } diff --git a/DependencyInjection/LexikTranslationExtension.php b/DependencyInjection/LexikTranslationExtension.php index 3d573f30..c714d9af 100644 --- a/DependencyInjection/LexikTranslationExtension.php +++ b/DependencyInjection/LexikTranslationExtension.php @@ -310,6 +310,10 @@ protected function registerTranslatorConfiguration(array $config, ContainerBuild $dirs[] = $dir; } + if (Kernel::MAJOR_VERSION >= 4 && is_dir($dir = $container->getParameter('kernel.project_dir').'/translations')) { + $dirs[] = $dir; + } + // Register translation resources if (count($dirs) > 0) { foreach ($dirs as $dir) { diff --git a/EventDispatcher/CleanTranslationCacheListener.php b/EventDispatcher/CleanTranslationCacheListener.php index 49844277..b96d7cad 100644 --- a/EventDispatcher/CleanTranslationCacheListener.php +++ b/EventDispatcher/CleanTranslationCacheListener.php @@ -65,6 +65,8 @@ public function onKernelRequest(GetResponseEvent $event) $lastUpdateTime = $this->storage->getLatestUpdatedAt(); if ($lastUpdateTime instanceof \DateTime) { + $this->checkCacheFolder(); + $finder = new Finder(); $finder->files() ->in($this->cacheDirectory.'/translations') @@ -109,4 +111,11 @@ private function isCacheExpired() return $expired; } + + private function checkCacheFolder() + { + if (!is_dir($dirName = $this->cacheDirectory.'/translations') && !mkdir($dirName) && !is_dir($dirName)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $dirName)); + } + } }