8000 bug #22255 [Translation] avoid creating cache files for fallback loca… · symfony/symfony@a200357 · GitHub
[go: up one dir, main page]

Skip to content

Commit a200357

Browse files
committed
bug #22255 [Translation] avoid creating cache files for fallback locales. (aitboudad)
This PR was merged into the 2.7 branch. Discussion ---------- [Translation] avoid creating cache files for fallback locales. | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21163 | License | MIT | Doc PR | ~ Commits ------- 22425b2 [Translation] avoid creating cache files for fallback locales.
2 parents cb49907 + 22425b2 commit a200357

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Translation/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
/*

src/Symfony/Component/Translation/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)
0