File tree 4 files changed +86
-1
lines changed 4 files changed +86
-1
lines changed Original file line number Diff line number Diff line change 1
1
CHANGELOG
2
2
=========
3
3
4
+ 2.7.0-DEV
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
+ protected $ translator ;
26
+
27
+ /**
28
+ * Constructor.
29
+ *
30
+ * @param TranslatorInterface $translator A Translator instance
31
+ */
32
+ public function __construct (TranslatorInterface $ translator )
33
+ {
34
+ $ this ->translator = $ translator ;
35
+ }
36
+
37
+ /**
38
+ * Warms up the cache.
39
+ *
40
+ * @param string $cacheDir The cache directory
41
+ */
42
+ public function warmUp ($ cacheDir )
43
+ {
44
+ if ($ this ->translator instanceof WarmableInterface) {
45
+ $ this ->translator ->warmUp ($ cacheDir );
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Checks whether this warmer is optional or not.
51
+ *
52
+ * @return bool always true
53
+ */
54
+ public function isOptional ()
55
+ {
56
+ return true ;
57
+ }
58
+ }
Original file line number Diff line number Diff line change 33
33
<parameter key =" translation.loader.class" >Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader</parameter >
34
34
<parameter key =" translation.extractor.class" >Symfony\Component\Translation\Extractor\ChainExtractor</parameter >
35
35
<parameter key =" translation.writer.class" >Symfony\Component\Translation\Writer\TranslationWriter</parameter >
36
+ <parameter key =" translation.warmer.class" >Symfony\Bundle\FrameworkBundle\CacheWarmer\TranslationsCacheWarmer</parameter >
36
37
</parameters >
37
38
38
39
<services >
152
153
<service id =" translation.extractor" class =" %translation.extractor.class%" />
153
154
154
155
<service id =" translation.writer" class =" %translation.writer.class%" />
156
+
157
+ <service id =" translation.warmer" class =" %translation.warmer.class%" public =" false" >
158
+ <argument type =" service" id =" translator" />
159
+ <tag name =" kernel.cache_warmer" />
160
+ </service >
155
161
</services >
156
162
</container >
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Translation ;
13
13
14
+ use Symfony \Component \HttpKernel \CacheWarmer \WarmableInterface ;
14
15
use Symfony \Component \Translation \Loader \LoaderInterface ;
15
16
use Symfony \Component \Translation \Exception \NotFoundResourceException ;
16
17
use Symfony \Component \Config \ConfigCache ;
22
23
*
23
24
* @api
24
25
*/
25
- class Translator implements TranslatorInterface, TranslatorBagInterface
26
+ class Translator implements TranslatorInterface, TranslatorBagInterface, WarmableInterface
26
27
{
27
28
/**
28
29
* @var MessageCatalogueInterface[]
@@ -491,4 +492,19 @@ protected function assertValidLocale($locale)
491
492
throw new \InvalidArgumentException (sprintf ('Invalid "%s" locale. ' , $ locale ));
492
493
}
493
494
}
495
+
496
+ /**
497
+ * @see WarmableInterface
498
+ *
499
+ * @param string $cacheDir only used for interface compatibility, $this->cacheDir is already defined
500
+ */
501
+ public function warmUp ($ cacheDir )
502
+ {
503
+ if ($ this ->locale !== null ) {
504
+ $ this ->loadCatalogue ($ this ->locale );
505
+ }
506
+ foreach ($ this ->fallbackLocales as $ locale ) {
507
+ $ this ->loadCatalogue ($ locale );
508
+ }
509
+ }
494
510
}
You can’t perform that action at this time.
0 commit comments