File tree Expand file tree Collapse file tree 4 files changed +84
-1
lines changed
src/Symfony/Bundle/FrameworkBundle Expand file tree Collapse file tree 4 files changed +84
-1
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 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 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,23 @@ 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
+
106
+ if (null !== $ this ->locale ) {
107
+ $ this ->loadCatalogue ($ this ->locale );
108
+ }
109
+
110
+ foreach ($ this ->getFallbackLocales () as $ locale ) {
111
+ // We need to reset the catalogues every time, otherwise file won't be generated
112
+ $ this ->catalogues = array ();
113
+ $ this ->loadCatalogue ($ locale );
114
+ }
115
+ }
116
+ }
97
117
}
You can’t perform that action at this time.
0 commit comments