Skip to content

Commit

Permalink
Sf4 fix (#331)
Browse files Browse the repository at this point in the history
* Use correct new symfony 4 translations directory

* Import command new sf4 directory structure

* Create translations cache dir
  • Loading branch information
rjwebdev authored and gilles-g committed Dec 17, 2018
1 parent cdd6296 commit 91d1844
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Command/ImportTranslationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/LexikTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions EventDispatcher/CleanTranslationCacheListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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));
}
}
}

0 comments on commit 91d1844

Please sign in to comment.