|
12 | 12 | namespace Translation\Bundle\Controller; |
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
| 15 | +use Symfony\Component\Finder\Finder; |
15 | 16 | use Symfony\Component\HttpFoundation\Request; |
16 | 17 | use Symfony\Component\HttpFoundation\Response; |
17 | 18 | use Translation\Bundle\Exception\MessageValidationException; |
@@ -44,28 +45,35 @@ public function editAction(Request $request, $configName, $locale) |
44 | 45 | $storage->update($message->convertToMessage($locale)); |
45 | 46 | } |
46 | 47 |
|
47 | | - $this->rebuildTranslations(); |
| 48 | + $this->rebuildTranslations($locale); |
48 | 49 |
|
49 | 50 | return new Response(); |
50 | 51 | } |
51 | 52 |
|
52 | 53 | /** |
53 | 54 | * Remove the Symfony translation cache and warm it up again. |
| 55 | + * |
| 56 | + * @param $locale |
54 | 57 | */ |
55 | | - private function rebuildTranslations() |
| 58 | + private function rebuildTranslations($locale) |
56 | 59 | { |
57 | 60 | $cacheDir = $this->getParameter('kernel.cache_dir'); |
58 | | - $translationDir = sprintf("%s/translations", $cacheDir); |
| 61 | + $translationDir = sprintf('%s/translations', $cacheDir); |
59 | 62 |
|
60 | 63 | $filesystem = $this->get('filesystem'); |
| 64 | + $finder = new Finder(); |
| 65 | + |
61 | 66 | if (!is_writable($translationDir)) { |
62 | 67 | throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $translationDir)); |
63 | 68 | } |
64 | 69 |
|
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); |
67 | 74 | } |
68 | 75 |
|
| 76 | + // Build them again |
69 | 77 | $this->get('translator')->warmUp(); |
70 | 78 | } |
71 | 79 |
|
|
0 commit comments