8000 Refresh catalogues when resources change · symfony/symfony@8659ab9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8659ab9

Browse files
committed
Refresh catalogues when resources change
1 parent 64d6ddb commit 8659ab9

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

src/Symfony/Component/Translation/Translator.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,9 @@ protected function initializeCatalogue($locale)
346346

347347
/**
348348
* @param string $locale
349+
* @param bool $forceRefresh
349350
*/
350-
private function initializeCacheCatalogue($locale)
351+
private function initializeCacheCatalogue($locale, $forceRefresh = false)
351352
{
352353
if (isset($this->catalogues[$locale])) {
353354
return;
@@ -361,7 +362,7 @@ private function initializeCacheCatalogue($locale)
361362

362363
$this->assertValidLocale($locale);
363364
$cache = new ConfigCache($this->cacheDir.'/catalogue.'.$locale.'.php', $this->debug);
364-
if (!$cache->isFresh()) {
365+
if ($forceRefresh || !$cache->isFresh()) {
365366
$this->initializeCatalogue($locale);
366367

367368
$fallbackContent = '';
@@ -392,13 +393,15 @@ private function initializeCacheCatalogue($locale)
392393
393394
use Symfony\Component\Translation\MessageCatalogue;
394395
396+
\$resourcesHash = '%s';
395397
\$catalogue = new MessageCatalogue('%s', %s);
396398
397399
%s
398-
return \$catalogue;
400+
return array(\$catalogue, \$resourcesHash);
399401
400402
EOF
401403
,
404+
$this->getResourcesHash($locale),
402405
$locale,
403406
var_export($this->catalogues[$locale]->all(), true),
404407
$fallbackContent
@@ -409,7 +412,30 @@ private function initializeCacheCatalogue($locale)
409412
return;
410413
}
411414

412-
$this->catalogues[$locale] = include $cache;
415+
$catalogue = include $cache;
416+
417+
/**
418+
* Old cache returns only the catalogue, without resourcesHash
419+
*/
420+
$resourcesHash = null;
421+
if (is_array($catalogue)) {
422+
list($catalogue, $resourcesHash) = $catalogue;
423+
}
424+
425+
if ($this->debug && $resourcesHash !== $this->getResourcesHash($locale)) {
426+
return $this->initializeCacheCatalogue($locale, true);
427+
}
428+
429+
$this->catalogues[$locale] = $catalogue;
430+
}
431+
432+
private function getResourcesHash($locale)
433+
{
434+
if (!isset($this->resources[$locale])) {
435+
return '';
436+
}
437+
438+
return sha1(serialize($this->resources[$locale]));
413439
}
414440

415441
private function doLoadCatalogue($locale)

0 commit comments

Comments
 (0)
0