@@ -109,7 +109,7 @@ public function testTransWithCachingWithInvalidLocale()
109
109
110
110
public function testLoadResourcesWithoutCaching ()
111
111
{
112
- $ loader = new \ Symfony \ Component \ Translation \ Loader \ YamlFileLoader ();
112
+ $ loader = new YamlFileLoader ();
113
113
$ resourceFiles = [
114
114
'fr ' => [
115
115
__DIR__ .'/../Fixtures/Resources/translations/messages.fr.yml ' ,
@@ -186,7 +186,7 @@ public function getDebugModeAndCacheDirCombinations()
186
186
187
187
public function testCatalogResourcesAreAddedForScannedDirectories ()
188
188
{
189
- $ loader = new \ Symfony \ Component \ Translation \ Loader \ YamlFileLoader ();
189
+ $ loader = new YamlFileLoader ();
19
341A
0
190
$ resourceFiles = [
191
191
'fr ' => [
192
192
__DIR__ .'/../Fixtures/Resources/translations/messages.fr.yml ' ,
@@ -329,9 +329,9 @@ protected function getContainer($loader)
329
329
return $ container ;
330
330
}
331
331
332
- public function getTranslator ($ loader , $ options = [], $ loaderFomat = 'loader ' , $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' , $ defaultLocale = 'en ' )
332
+ public function getTranslator ($ loader , $ options = [], $ loaderFomat = 'loader ' , $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' , $ defaultLocale = 'en ' , array $ enabledLocales = [] )
333
333
{
334
- $ translator = $ this ->createTranslator ($ loader , $ options , $ translatorClass , $ loaderFomat , $ defaultLocale );
334
+ $ translator = $ this ->createTranslator ($ loader , $ options , $ translatorClass , $ loaderFomat , $ defaultLocale, $ enabledLocales );
335
335
336
336
if ('loader ' === $ loaderFomat ) {
337
337
$ translator ->addResource ('loader ' , 'foo ' , 'fr ' );
@@ -348,7 +348,7 @@ public function getTranslator($loader, $options = [], $loaderFomat = 'loader', $
348
348
349
349
public function testWarmup ()
350
350
{
351
- $ loader = new \ Symfony \ Component \ Translation \ Loader \ YamlFileLoader ();
351
+ $ loader = new YamlFileLoader ();
352
352
$ resourceFiles = [
353
353
'fr ' => [
354
354
__DIR__ .'/../Fixtures/Resources/translations/messages.fr.yml ' ,
@@ -371,9 +371,34 @@ public function testWarmup()
371
371
$ this ->assertEquals ('répertoire ' , $ translator ->trans ('folder ' ));
372
372
}
373
373
374
+ public function testEnabledLocales ()
375
+ {
376
+ $ loader = new YamlFileLoader ();
377
+ $ resourceFiles = [
378
+ 'fr ' => [
379
+ __DIR__ .'/../Fixtures/Resources/translations/messages.fr.yml ' ,
380
+ ],
381
+ ];
382
+
383
+ // prime the cache without configuring the enabled locales
384
+ $ translator = $ this ->getTranslator ($ loader , ['cache_dir ' => $ this ->tmpDir , 'resource_files ' => $ resourceFiles ], 'yml ' , Translator::class, 'en ' , []);
385
+ $ translator ->setFallbackLocales (['fr ' ]);
386
+ $ translator ->warmup ($ this ->tmpDir );
387
+
388
+ $ this ->assertCount (2 , glob ($ this ->tmpDir .'/catalogue.*.*.php ' ), 'Both "en" and "fr" catalogues are generated. ' );
389
+
390
+ // prime the cache and configure the enabled locales
391
+ $ this ->deleteTmpDir ();
392
+ $ translator = $ this ->getTranslator ($ loader , ['cache_dir ' => $ this ->tmpDir , 'resource_files ' => $ resourceFiles ], 'yml ' , Translator::class, 'en ' , ['fr ' ]);
393
+ $ translator ->setFallbackLocales (['fr ' ]);
394
+ $ translator ->warmup ($ this ->tmpDir );
395
+
396
+ $ this ->assertCount (1 , glob ($ this ->tmpDir .'/catalogue.*.*.php ' ), 'Only the "fr" catalogue is generated. ' );
397
+ }
398
+
374
399
public function testLoadingTranslationFilesWithDotsInMessageDomain ()
375
400
{
376
- $ loader = new \ Symfony \ Component \ Translation \ Loader \ YamlFileLoader ();
401
+ $ loader = new YamlFileLoader ();
377
402
$ resourceFiles = [
378
403
'en ' => [
379
404
__DIR__ .'/../Fixtures/Resources/translations/domain.with.dots.en.yml ' ,
@@ -386,14 +411,15 @@ public function testLoadingTranslationFilesWithDotsInMessageDomain()
386
411
$ this ->assertEquals ('It works! ' , $ translator ->trans ('message ' , [], 'domain.with.dots ' ));
387
412
}
388
413
389
- private function createTranslator ($ loader , $ options , $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' , $ loaderFomat = 'loader ' , $ defaultLocale = 'en ' )
414
+ private function createTranslator ($ loader , $ options , $ translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator ' , $ loaderFomat = 'loader ' , $ defaultLocale = 'en ' , array $ enabledLocales = [] )
390
415
{
391
416
if (null === $ defaultLocale ) {
392
417
return new $ translatorClass (
393
418
$ this ->getContainer ($ loader ),
394
419
new MessageFormatter (),
395
420
[$ loaderFomat => [$ loaderFomat ]],
396
- $ options
421
+ $ options ,
422
+ $ enabledLocales
397
423
);
398
424
}
399
425
@@ -402,7 +428,8 @@ private function createTranslator($loader, $options, $translatorClass = '\Symfon
402
428
new MessageFormatter (),
403
429
$ defaultLocale ,
404
430
[$ loaderFomat => [$ loaderFomat ]],
405
- $ options
431
+ $ options ,
432
+ $ enabledLocales
406
433
);
407
434
}
408
435
}
0 commit comments