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
This commit is contained in:
commit
85827f32e4
@ -1128,12 +1128,12 @@ class FrameworkExtension extends Extension
|
|||||||
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
|
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
|
||||||
$rootDir = $container->getParameter('kernel.root_dir');
|
$rootDir = $container->getParameter('kernel.root_dir');
|
||||||
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
|
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
|
||||||
if (is_dir($dir = $bundle['path'].'/Resources/translations')) {
|
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
} else {
|
} else {
|
||||||
$nonExistingDirs[] = $dir;
|
$nonExistingDirs[] = $dir;
|
||||||
}
|
}
|
||||||
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
|
if ($container->fileExists($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
|
||||||
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
|
||||||
$dirs[] = $dir;
|
$dirs[] = $dir;
|
||||||
} else {
|
} else {
|
||||||
@ -1142,7 +1142,7 @@ class FrameworkExtension extends Extension
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($config['paths'] as $dir) {
|
foreach ($config['paths'] as $dir) {
|
||||||
if (is_dir($dir)) {
|
if ($container->fileExists($dir)) {
|
||||||
$dirs[] = $transPaths[] = $dir;
|
$dirs[] = $transPaths[] = $dir;
|
||||||
} else {
|
} else {
|
||||||
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
|
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
|
||||||
@ -1157,13 +1157,13 @@ class FrameworkExtension extends Extension
|
|||||||
$container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths);
|
$container->getDefinition('console.command.translation_update')->replaceArgument(6, $transPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($defaultDir)) {
|
if ($container->fileExists($defaultDir)) {
|
||||||
$dirs[] = $defaultDir;
|
$dirs[] = $defaultDir;
|
||||||
} else {
|
} else {
|
||||||
$nonExistingDirs[] = $defaultDir;
|
$nonExistingDirs[] = $defaultDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($dir = $rootDir.'/Resources/translations')) {
|
if ($container->fileExists($dir = $rootDir.'/Resources/translations')) {
|
||||||
if ($dir !== $defaultDir) {
|
if ($dir !== $defaultDir) {
|
||||||
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
|
@trigger_error(sprintf('Translations directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $dir, $defaultDir), E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@ use Symfony\Component\Cache\Adapter\DoctrineAdapter;
|
|||||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
use Symfony\Component\Cache\Adapter\ProxyAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
use Symfony\Component\Cache\Adapter\RedisAdapter;
|
||||||
use Symfony\Component\Config\Resource\DirectoryResource;
|
|
||||||
use Symfony\Component\Config\Resource\FileExistenceResource;
|
|
||||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
|
use Symfony\Component\DependencyInjection\Compiler\ResolveInstanceofConditionalsPass;
|
||||||
@ -840,17 +838,6 @@ abstract class FrameworkExtensionTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
|
$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');
|
||||||
|
|
||||||
$resources = $container->getResources();
|
|
||||||
foreach ($resources as $resource) {
|
|
||||||
if ($resource instanceof DirectoryResource) {
|
|
||||||
$this->assertNotContains('translations', $resource->getResource());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($resource instanceof FileExistenceResource) {
|
|
||||||
$this->assertNotContains('translations', $resource->getResource());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user