Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Translation] add bundles trans paths into commands (extract/pull/push) #52454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations') || $container->fileExists($dir = $bundle['path'].'/translations')) {
$dirs[] = $dir;
$dirs[] = $transPaths[] = $dir;
} else {
$nonExistingDirs[] = $dir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,19 @@ public function testMessengerWithDisabledResetOnMessage()

public function testTranslator()
{
$container = $this->createContainerFromFile('full');
require_once __DIR__.'/Fixtures/TestBundle/TestBundle.php';

$container = $this->createContainerFromFile('full', [
'kernel.bundles' => [
'FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle',
'TestBundle' => 'Symfony\\Bundle\\FrameworkBundle\\Tests\\TestBundle',
],
'kernel.bundles_metadata' => [
'FrameworkBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle', 'path' => __DIR__.'/../..'],
'TestBundle' => ['namespace' => 'Symfony\\Bundle\\FrameworkBundle\\Tests', 'path' => __DIR__.'/Fixtures/TestBundle'],
],
]);

$this->assertTrue($container->hasDefinition('translator.default'), '->registerTranslatorConfiguration() loads translation.php');
$this->assertEquals('translator.default', (string) $container->getAlias('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
$options = $container->getDefinition('translator.default')->getArgument(4);
Expand Down Expand Up @@ -1115,6 +1127,11 @@ public function testTranslator()
'->registerTranslatorConfiguration() finds translation resources with dots in domain'
);
$this->assertContains(strtr(__DIR__.'/translations/security.en.yaml', '/', \DIRECTORY_SEPARATOR), $files);
$this->assertContains(
strtr(__DIR__.'/Fixtures/TestBundle/Resources/translations/messages.en.yaml', '/', \DIRECTORY_SEPARATOR),
$files,
'->registerTranslatorConfiguration() finds translation resources within bundles'
);

$positionOverridingTranslationFile = array_search(strtr(realpath(__DIR__.'/translations/security.en.yaml'), '/', \DIRECTORY_SEPARATOR), $files);

Expand All @@ -1140,7 +1157,38 @@ function ($directory) {

$this->assertNotEmpty($nonExistingDirectories, 'FrameworkBundle should pass non existing directories to Translator');

$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][3]);
$this->assertSame('Fixtures/translations', $options['cache_vary']['scanned_directories'][4]);

$transPaths = $container->getDefinition('console.command.translation_extract')->getArgument(6);

$ref = new \ReflectionClass(Validation::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR),
$transPaths,
'->registerTranslatorConfiguration() finds Validator translation resources to extract'
);
$ref = new \ReflectionClass(Form::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR),
$transPaths,
'->registerTranslatorConfiguration() finds Form translation resources to extract'
);
$ref = new \ReflectionClass(Security::class);
$this->assertContains(
strtr(\dirname($ref->getFileName()).'/Resources/translations', '/', \DIRECTORY_SEPARATOR),
$transPaths,
'->registerTranslatorConfiguration() finds Security translation resources to extract'
);
$this->assertContains(
strtr(__DIR__.'/Fixtures/translations', '/', \DIRECTORY_SEPARATOR),
$transPaths,
'->registerTranslatorConfiguration() finds translation resources in custom paths to extract'
);
$this->assertContains(
strtr(__DIR__.'/Fixtures/TestBundle/Resources/translations', '/', \DIRECTORY_SEPARATOR),
$transPaths,
'->registerTranslatorConfiguration() finds translation resources with in bundles to extract'
);
}

public function testTranslatorMultipleFallbacks()
Expand Down