Skip to content

Commit 8a94cd2

Browse files
committed
[Translation] avoid creating cache files for fallback locales.
1 parent 560c640 commit 8a94cd2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Tests/TranslatorCacheTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCac
149149
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
150150
}
151151

152+
public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
153+
{
154+
$translator = new Translator('a', null, $this->tmpDir);
155+
$translator->setFallbackLocales(array('b'));
156+
$translator->trans('bar');
157+
158+
$cachedFiles = glob($this->tmpDir.'/*.php');
159+
160+
$this->assertCount(1, $cachedFiles);
161+
}
162+
152163
public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
153164
{
154165
/*

Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ private function loadFallbackCatalogues($locale)
420420

421421
foreach ($this->computeFallbackLocales($locale) as $fallback) {
422422
if (!isset($this->catalogues[$fallback])) {
423-
$this->loadCatalogue($fallback);
423+
$this->initializeCatalogue($fallback);
424424
}
425425

426426
$fallbackCatalogue = new MessageCatalogue($fallback, $this->catalogues[$fallback]->all());

0 commit comments

Comments
 (0)