Skip to content

Commit 8314733

Browse files
Merge branch '4.4' into 5.2
* 4.4: scan directories for translations sequentially
2 parents 7a0afbe + 08cf386 commit 8314733

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,24 +1220,26 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12201220
// Register translation resources
12211221
if ($dirs) {
12221222
$files = [];
1223-
$finder = Finder::create()
1224-
->followLinks()
1225-
->files()
1226-
->filter(function (\SplFileInfo $file) {
1227-
return 2 <= substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
1228-
})
1229-
->in($dirs)
1230-
->sortByName()
1231-
;
12321223

1233-
foreach ($finder as $file) {
1234-
$fileNameParts = explode('.', basename($file));
1235-
$locale = $fileNameParts[\count($fileNameParts) - 2];
1236-
if (!isset($files[$locale])) {
1237-
$files[$locale] = [];
1238-
}
1224+
foreach ($dirs as $dir) {
1225+
$finder = Finder::create()
1226+
->followLinks()
1227+
->files()
1228+
->filter(function (\SplFileInfo $file) {
1229+
return 2 <= substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
1230+
})
1231+
->in($dir)
1232+
->sortByName()
1233+
;
1234+
foreach ($finder as $file) {
1235+
$fileNameParts = explode('.', basename($file));
1236+
$locale = $fileNameParts[\count($fileNameParts) - 2];
1237+
if (!isset($files[$locale])) {
1238+
$files[$locale] = [];
1239+
}
12391240

1240-
$files[$locale][] = (string) $file;
1241+
$files[$locale][] = (string) $file;
1242+
}
12411243
}
12421244

12431245
$projectDir = $container->getParameter('kernel.project_dir');

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,19 @@ public function testTranslator()
836836
$files,
837837
'->registerTranslatorConfiguration() finds translation resources with dots in domain'
838838
);
839+
$this->assertContains(strtr(__DIR__.'/translations/security.en.yaml', '/', \DIRECTORY_SEPARATOR), $files);
840+
841+
$positionOverridingTranslationFile = array_search(strtr(realpath(__DIR__.'/translations/security.en.yaml'), '/', \DIRECTORY_SEPARATOR), $files);
842+
843+
if (false !== $positionCoreTranslationFile = array_search(strtr(realpath(__DIR__.'/../../../../Component/Security/Core/Resources/translations/security.en.xlf'), '/', \DIRECTORY_SEPARATOR), $files)) {
844+
$this->assertContains(strtr(realpath(__DIR__.'/../../../../Component/Security/Core/Resources/translations/security.en.xlf'), '/', \DIRECTORY_SEPARATOR), $files);
845+
} else {
846+
$this->assertContains(strtr(realpath(__DIR__.'/../../vendor/symfony/security-core/Resources/translations/security.en.xlf'), '/', \DIRECTORY_SEPARATOR), $files);
847+
848+
$positionCoreTranslationFile = array_search(strtr(realpath(__DIR__.'/../../vendor/symfony/security-core/Resources/translations/security.en.xlf'), '/', \DIRECTORY_SEPARATOR), $files);
849+
}
850+
851+
$this->assertGreaterThan($positionCoreTranslationFile, $positionOverridingTranslationFile);
839852

840853
$calls = $container->getDefinition('translator.default')->getMethodCalls();
841854
$this->assertEquals(['fr'], $calls[1][1][0]);

Tests/DependencyInjection/translations/security.en.yaml

Whitespace-only changes.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"symfony/mime": "^4.4|^5.0",
5353
"symfony/process": "^4.4|^5.0",
5454
"symfony/security-bundle": "^5.1",
55+
"symfony/security-core": "^4.4|^5.2",
5556
"symfony/security-csrf": "^4.4|^5.0",
5657
"symfony/security-http": "^4.4|^5.0",
5758
"symfony/serializer": "^5.2",

0 commit comments

Comments
 (0)