Skip to content

Commit e7119fe

Browse files
bug #32708 Recompile container when translations directory changes (pierredup)
This PR was merged into the 4.3 branch. Discussion ---------- Recompile container when translations directory changes | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32706 | License | MIT | Doc PR | N/A The list of translation resources is cached by the container, so when adding a new translation file, the container needs to be recompiled otherwise the translator won't know about the new file. Commits ------- 7f2e7e2e9a Recompile container when translations directory changes
2 parents f4c4d29 + 035f268 commit e7119fe

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,12 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11281128
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
11291129
$rootDir = $container->getParameter('kernel.root_dir');
11301130
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
1131-
if (is_dir($dir = $bundle['path'].'/Resources/translations')) {
1131+
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
11321132
$dirs[] = $dir;
11331133
} else {
11341134
$nonExistingDirs[] = $dir;
11351135
}
1136-
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
1136+
if ($container->fileExists($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
11371137
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
11381138
$dirs[] = $dir;
11391139
} else {
@@ -1142,7 +1142,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11421142
}
11431143

11441144
foreach ($config['paths'] as $dir) {
1145-
if (is_dir($dir)) {
1145+
if ($container->fileExists($dir)) {
11461146
$dirs[] = $transPaths[] = $dir;
11471147
} else {
11481148
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
@@ -1157,13 +1157,13 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11571157
$container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths);
11581158
}
11591159

1160-
if (is_dir($defaultDir)) {
1160+
if ($container->fileExists($defaultDir)) {
11611161
$dirs[] = $defaultDir;
11621162
} else {
11631163
$nonExistingDirs[] = $defaultDir;
11641164
}
11651165

1166-
if (is_dir($dir = $rootDir.'/Resources/translations')) {
1166+
if ($container->fileExists($dir = $rootDir.'/Resources/translations')) {
11671167
if ($dir !== $defaultDir) {
11681168
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
11691169
}

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
2525
use Symfony\Component\Cache\Adapter\ProxyAdapter;
2626
use Symfony\Component\Cache\Adapter\RedisAdapter;
27-
use Symfony\Component\Config\Resource\DirectoryResource;
28-
use Symfony\Component\Config\Resource\FileExistenceResource;
2927
use Symfony\Component\DependencyInjection\ChildDefinition;
3028
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
3129
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
@@ -840,17 +838,6 @@ function ($directory) {
840838
);
841839

842840
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
843-
844-
$resources = $container->getResources();
845-
foreach ($resources as $resource) {
846-
if ($resource instanceof DirectoryResource) {
847-
$this->assertNotContains('translations', $resource->getResource());
848-
}
849-
850-
if ($resource instanceof FileExistenceResource) {
851-
$this->assertNotContains('translations', $resource->getResource());
852-
}
853-
}
854841
}
855842

856843
/**

0 commit comments

Comments
 (0)