Skip to content

Commit

Permalink
bug #22255 [Translation] avoid creating cache files for fallback loca…
Browse files Browse the repository at this point in the history
…les. (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.
  • Loading branch information
fabpot committed Apr 5, 2017
2 parents cb49907 + 22425b2 commit a200357
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php
Expand Up @@ -149,6 +149,17 @@ public function testDifferentTranslatorsForSameLocaleDoNotOverwriteEachOthersCac
$this->assertEquals('OK', $translator->trans($msgid), '-> the cache was overwritten by another translator instance in '.($debug ? 'debug' : 'production'));
}

public function testGeneratedCacheFilesAreOnlyBelongRequestedLocales()
{
$translator = new Translator('a', null, $this->tmpDir);
$translator->setFallbackLocales(array('b'));
$translator->trans('bar');

$cachedFiles = glob($this->tmpDir.'/*.php');

$this->assertCount(1, $cachedFiles);
}

public function testDifferentCacheFilesAreUsedForDifferentSetsOfFallbackLocales()
{
/*
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Translation/Translator.php
Expand Up @@ -420,7 +420,7 @@ private function loadFallbackCatalogues($locale)

foreach ($this->computeFallbackLocales($locale) as $fallback) {
if (!isset($this->catalogues[$fallback])) {
$this->loadCatalogue($fallback);
$this->initializeCatalogue($fallback);
}

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

0 comments on commit a200357

Please sign in to comment.