File tree Expand file tree Collapse file tree 6 files changed +86
-2
lines changed
src/Symfony/Bundle/FrameworkBundle
DependencyInjection/Compiler
Tests/DependencyInjection/Compiler Expand file tree Collapse file tree 6 files changed +86
-2
lines changed Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=========
3
3
4
+ 2.7.0
5
+ -----
6
+
7
+ * Added ` TranslationsCacheWarmer ` to create catalogues at warmup
8
+
4
9
2.6.0
5
10
-----
6
11
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \CacheWarmer ;
13
+
14
+ use Symfony \Component \HttpKernel \CacheWarmer \CacheWarmerInterface ;
15
+ use Symfony \Component \HttpKernel \CacheWarmer \WarmableInterface ;
16
+ use Symfony \Component \Translation \TranslatorInterface ;
17
+
18
+ /**
19
+ * Generates the catalogues for translations.
20
+ *
21
+ * @author Xavier Leune <xavier.leune@gmail.com>
22
+ */
23
+ class TranslationsCacheWarmer implements CacheWarmerInterface
24
+ {
25
+ private $ translator ;
26
+
27
+ /**
28
+ *
29
+ * @param TranslatorInterface $translator A Translator instance
30
+ */
31
+ public function __construct (TranslatorInterface $ translator )
32
+ {
33
+ $ this ->translator = $ translator ;
34
+ }
35
+
36
+ /**
37
+ * {@inheritdoc}
38
+ */
39
+ public function warmUp ($ cacheDir )
40
+ {
41
+ if ($ this ->translator instanceof WarmableInterface) {
42
+ $ this ->translator ->warmUp ($ cacheDir );
43
+ }
44
+ }
45
+
46
+ /**
47
+ * {@inheritdoc}
48
+ */
49
+ public function isOptional ()
50
+ {
51
+ return true ;
52
+ }
53
+ }
Original file line number Diff line number Diff line change 13
13
14
14
use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
15
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
16
+ use Symfony \Component \DependencyInjection \Reference ;
16
17
17
18
/**
18
19
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
@@ -38,6 +39,7 @@ public function process(ContainerBuilder $container)
38
39
$ refClass = new \ReflectionClass ($ class );
39
40
if ($ refClass ->implementsInterface ('Symfony\Component\Translation\TranslatorInterface ' ) && $ refClass ->implementsInterface ('Symfony\Component\Translation\TranslatorBagInterface ' )) {
40
41
$ container ->getDefinition ('translator.logging ' )->setDecoratedService ('translator ' );
42
+ $ container ->getDefinition ('translation.warmer ' )->replaceArgument (0 , new Reference ('translator.logging.inner ' ));
41
43
}
42
44
}
43
45
}
Original file line number Diff line number Diff line change 152
152
<service id =" translation.extractor" class =" %translation.extractor.class%" />
153
153
154
154
<service id =" translation.writer" class =" %translation.writer.class%" />
155
+
156
+ <service id =" translation.warmer" class =" Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer" public =" false" >
157
+ <argument type =" service" id =" translator" />
158
+ <tag name =" kernel.cache_warmer" />
159
+ </service >
155
160
</services >
156
161
</container >
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public function testProcess()
35
35
->method ('getAlias ' )
36
36
->will ($ this ->returnValue ('translation.default ' ));
37
37
38
- $ container ->expects ($ this ->exactly (2 ))
38
+ $ container ->expects ($ this ->exactly (3 ))
39
39
->method ('getDefinition ' )
40
40
->will ($ this ->returnValue ($ definition ));
41
41
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Translation ;
13
13
14
+ use Symfony \Component \HttpKernel \CacheWarmer \WarmableInterface ;
14
15
use Symfony \Component \Translation \Translator as BaseTranslator ;
15
16
use Symfony \Component \Translation \MessageSelector ;
16
17
use Symfony \Component \DependencyInjection \ContainerInterface ;
20
21
*
21
22
* @author Fabien Potencier <fabien@symfony.com>
22
23
*/
23
- class Translator extends BaseTranslator
24
+ class Translator extends BaseTranslator implements WarmableInterface
24
25
{
25
26
protected $ container ;
26
27
protected $ loaderIds ;
@@ -94,4 +95,22 @@ private function loadResources()
94
95
unset($ this ->resourceFiles [$ key ]);
95
96
}
96
97
}
98
+
99
+ /**
100
+ * {@inheritdoc}
101
+ */
102
+ public function warmUp ($ cacheDir )
103
+ {
104
+ if (null !== $ this ->options ['cache_dir ' ]) {
105
+ if (null !== $ this ->locale ) {
106
+ $ this ->loadCatalogue ($ this ->locale );
107
+ }
108
+
109
+ foreach ($ this ->getFallbackLocales () as $ locale ) {
110
+ // We need to reset the catalogues every time, otherwise file won't be generated
111
+ $ this ->catalogues = array ();
112
+ $ this ->loadCatalogue ($ locale );
113
+ }
114
+ }
115
+ }
97
116
}
You can’t perform that action at this time.
0 commit comments