Skip to content

Commit 2554dd9

Browse files
Merge branch '3.4'
* 3.4: [TwigBridge] Fixed the .form-check-input class in the bs4 templates [Console] Fix traversable autocomplete values [SecurityBundle] Improve deprecations [DI] Friendlier name for generated container in "as_files" mode [Debug] Remove false-positive deprecation from DebugClassLoader [SecurityBundle] Add missing quotes in deprecation messages [ExpressionLanguage] Fix PhpDoc type-hints on Token value bumped Symfony version to 3.3.12 Add default translations path option and convention updated VERSION for 3.3.11 updated CHANGELOG for 3.3.11 bumped Symfony version to 2.8.30 updated VERSION for 2.8.29 updated CHANGELOG for 2.8.29 bumped Symfony version to 2.7.37 updated VERSION for 2.7.36 update CONTRIBUTORS for 2.7.36 updated CHANGELOG for 2.7.36
2 parents 16c4d18 + a814f30 commit 2554dd9

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ CHANGELOG
2727
3.4.0
2828
-----
2929

30+
* Added `translator.default_path` option and parameter
3031
* Session `use_strict_mode` is now enabled by default and the corresponding option has been deprecated
3132
* Made the `cache:clear` command to *not* clear "app" PSR-6 cache pools anymore,
3233
but to still clear "system" ones; use the `cache:pool:clear` command to clear "app" pools instead

DependencyInjection/Configuration.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode)
624624
->end()
625625
->booleanNode('logging')->defaultValue($this->debug)->end()
626626
->scalarNode('formatter')->defaultValue('translator.formatter.default')->end()
627+
->scalarNode('default_path')
628+
->info('The default path used to load translations')
629+
->defaultValue('%kernel.project_dir%/config/translations')
630+
->end()
627631
->arrayNode('paths')
628632
->prototype('scalar')->end()
629633
->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
872872
$translator->addMethodCall('setFallbackLocales', array($config['fallbacks']));
873873

874874
$container->setParameter('translator.logging', $config['logging']);
875+
$container->setParameter('translator.default_path', $config['default_path']);
875876

876877
// Discover translation directories
877878
$dirs = array();
@@ -890,11 +891,15 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
890891

891892
$dirs[] = dirname(dirname($r->getFileName())).'/Resources/translations';
892893
}
894+
$defaultDir = $container->getParameterBag()->resolveValue($config['default_path']);
893895
$rootDir = $container->getParameter('kernel.root_dir');
894896
foreach ($container->getParameter('kernel.bundles_metadata') as $name => $bundle) {
895897
if ($container->fileExists($dir = $bundle['path'].'/Resources/translations')) {
896898
$dirs[] = $dir;
897899
}
900+
if ($container->fileExists($dir = $defaultDir.'/'.$name)) {
901+
$dirs[] = $dir;
902+
}
898903
if ($container->fileExists($dir = $rootDir.sprintf('/Resources/%s/translations', $name))) {
899904
$dirs[] = $dir;
900905
}
@@ -908,6 +913,9 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
908913
}
909914
}
910915

916+
if ($container->fileExists($defaultDir)) {
917+
$dirs[] = $defaultDir;
918+
}
911919
if ($container->fileExists($dir = $rootDir.'/Resources/translations')) {
912920
$dirs[] = $dir;
913921
}

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected static function getBundleDefaultConfig()
155155
'logging' => true,
156156
'formatter' => 'translator.formatter.default',
157157
'paths' => array(),
158+
'default_path' => '%kernel.project_dir%/config/translations',
158159
),
159160
'validation' => array(
160161
'enabled' => !class_exists(FullStack::class),

Tests/DependencyInjection/Fixtures/yml/full.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ framework:
4242
translator:
4343
enabled: true
4444
fallback: fr
45+
default_path: '%kernel.root_dir%/config/translations'
4546
paths: ['%kernel.root_dir%/Fixtures/translations']
4647
validation:
4748
enabled: true

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ public function testTranslator()
496496
$files,
497497
'->registerTranslatorConfiguration() finds translation resources in custom paths'
498498
);
499+
$this->assertContains(
500+
strtr(__DIR__.'/config/translations/test_default.en.xlf', '/', DIRECTORY_SEPARATOR),
501+
$files,
502+
'->registerTranslatorConfiguration() finds translation resources in default path'
503+
);
499504

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

Tests/DependencyInjection/config/translations/test_default.en.xlf

Whitespace-only changes.

0 commit comments

Comments
 (0)