Skip to content

Commit aeda72c

Browse files
Only remove the translation cache for the edited locale
1 parent 24283d0 commit aeda72c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Controller/EditInPlaceController.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Translation\Bundle\Controller;
1313

1414
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15+
use Symfony\Component\Finder\Finder;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Translation\Bundle\Exception\MessageValidationException;
@@ -44,28 +45,35 @@ public function editAction(Request $request, $configName, $locale)
4445
$storage->update($message->convertToMessage($locale));
4546
}
4647

47-
$this->rebuildTranslations();
48+
$this->rebuildTranslations($locale);
4849

4950
return new Response();
5051
}
5152

5253
/**
5354
* Remove the Symfony translation cache and warm it up again.
55+
*
56+
* @param $locale
5457
*/
55-
private function rebuildTranslations()
58+
private function rebuildTranslations($locale)
5659
{
5760
$cacheDir = $this->getParameter('kernel.cache_dir');
58-
$translationDir = sprintf("%s/translations", $cacheDir);
61+
$translationDir = sprintf('%s/translations', $cacheDir);
5962

6063
$filesystem = $this->get('filesystem');
64+
$finder = new Finder();
65+
6166
if (!is_writable($translationDir)) {
6267
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $translationDir));
6368
}
6469

65-
if ($filesystem->exists($translationDir)) {
66-
$filesystem->remove($translationDir);
70+
// Remove the translations for this locale
71+
$files = $finder->files()->name('*.'.$locale.'.*')->in($translationDir);
72+
foreach ($files as $file) {
73+
$filesystem->remove($file);
6774
}
6875

76+
// Build them again
6977
$this->get('translator')->warmUp();
7078
}
7179

0 commit comments

Comments
 (0)