From 8b2d9a8d4d67d4065aa3c14b7c042ba0d2a06308 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Sat, 21 Jun 2014 22:28:07 +0100 Subject: [PATCH 1/2] [FrameworkBundle][Translation] moved cache to Translation component [Translation][Cache] removed accessors for options. --- .../Translation/Translator.php | 82 +-------- .../Component/Translation/CHANGELOG.md | 4 + .../Translation/Tests/TranslatorCacheTest.php | 169 ++++++++++++++++++ .../Component/Translation/Translator.php | 103 ++++++++++- 4 files changed, 279 insertions(+), 79 deletions(-) create mode 100644 src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 305d89deb02e1..4751f46e0c945 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -14,7 +14,6 @@ use Symfony\Component\Translation\Translator as BaseTranslator; use Symfony\Component\Translation\MessageSelector; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Config\ConfigCache; /** * Translator. @@ -24,10 +23,6 @@ class Translator extends BaseTranslator { protected $container; - protected $options = array( - 'cache_dir' => null, - 'debug' => false, - ); protected $loaderIds; /** @@ -50,14 +45,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele $this->container = $container; $this->loaderIds = $loaderIds; - // check option names - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { - throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff))); - } - - $this->options = array_merge($this->options, $options); - - parent::__construct(null, $selector); + parent::__construct(null, $selector, $options); } /** @@ -80,72 +68,10 @@ public function getLocale() /** * {@inheritdoc} */ - protected function loadCatalogue($locale) + protected function initializeCatalogue($locale) { - if (isset($this->catalogues[$locale])) { - return; - } - - if (null === $this->options['cache_dir']) { - $this->initialize(); - - return parent::loadCatalogue($locale); - } - - $this->assertValidLocale($locale); - - $cache = new ConfigCache($this->options['cache_dir'].'/catalogue.'.$locale.'.php', $this->options['debug']); - if (!$cache->isFresh()) { - $this->initialize(); - - parent::loadCatalogue($locale); - - $fallbackContent = ''; - $current = ''; - $replacementPattern = '/[^a-z0-9_]/i'; - foreach ($this->computeFallbackLocales($locale) as $fallback) { - $fallbackSuffix = ucfirst(preg_replace($replacementPattern, '_', $fallback)); - $currentSuffix = ucfirst(preg_replace($replacementPattern, '_', $current)); - - $fallbackContent .= sprintf(<<addFallbackCatalogue(\$catalogue%s); - - -EOF - , - $fallbackSuffix, - $fallback, - var_export($this->catalogues[$fallback]->all(), true), - $currentSuffix, - $fallbackSuffix - ); - $current = $fallback; - } - - $content = sprintf(<<catalogues[$locale]->all(), true), - $fallbackContent - ); - - $cache->write($content, $this->catalogues[$locale]->getResources()); - - return; - } - - $this->catalogues[$locale] = include $cache; + $this->initialize(); + parent::initializeCatalogue($locale); } protected function initialize() diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index c5f41c84a5a44..e6b39eff7c54b 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +2.6.0 +----- + * added possibility to cache catalogues + 2.5.0 ----- diff --git a/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php b/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php new file mode 100644 index 0000000000000..cf6da3d03c185 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php @@ -0,0 +1,169 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Translation\Tests; + +use Symfony\Component\Translation\Translator; +use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\MessageSelector; + +class TranslatorCacheTest extends \PHPUnit_Framework_TestCase +{ + protected $tmpDir; + + protected function setUp() + { + $this->tmpDir = sys_get_temp_dir().'/sf2_translation'; + $this->deleteTmpDir(); + } + + public function tearDown() + { + $this->deleteTmpDir(); + } + + protected function deleteTmpDir() + { + if (!file_exists($dir = $this->tmpDir)) { + return; + } + + $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->tmpDir), \RecursiveIteratorIterator::CHILD_FIRST); + foreach ($iterator as $path) { + if (preg_match('#[/\\\\]\.\.?$#', $path->__toString())) { + continue; + } + if ($path->isDir()) { + rmdir($path->__toString()); + } else { + unlink($path->__toString()); + } + } + rmdir($this->tmpDir); + } + + public function testTransWithoutCaching() + { + $translator = $this->getTranslator($this->getLoader()); + $translator->setLocale('fr'); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + + $this->assertEquals('foo (FR)', $translator->trans('foo')); + $this->assertEquals('bar (EN)', $translator->trans('bar')); + $this->assertEquals('foobar (ES)', $translator->trans('foobar')); + $this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0)); + $this->assertEquals('no translation', $translator->trans('no translation')); + $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); + $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + } + + public function testTransWithCaching() + { + // prime the cache + $translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir)); + $translator->setLocale('fr'); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + + $this->assertEquals('foo (FR)', $translator->trans('foo')); + $this->assertEquals('bar (EN)', $translator->trans('bar')); + $this->assertEquals('foobar (ES)', $translator->trans('foobar')); + $this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0)); + $this->assertEquals('no translation', $translator->trans('no translation')); + $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); + $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + + // do it another time as the cache is primed now + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir)); + $translator->setLocale('fr'); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + + $this->assertEquals('foo (FR)', $translator->trans('foo')); + $this->assertEquals('bar (EN)', $translator->trans('bar')); + $this->assertEquals('foobar (ES)', $translator->trans('foobar')); + $this->assertEquals('choice 0 (EN)', $translator->transChoice('choice', 0)); + $this->assertEquals('no translation', $translator->trans('no translation')); + $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); + $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + } + + protected function getCatalogue($locale, $messages) + { + $catalogue = new MessageCatalogue($locale); + foreach ($messages as $key => $translation) { + $catalogue->set($key, $translation); + } + + return $catalogue; + } + + protected function getLoader() + { + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $loader + ->expects($this->at(0)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('fr', array( + 'foo' => 'foo (FR)', + )))) + ; + $loader + ->expects($this->at(1)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('en', array( + 'foo' => 'foo (EN)', + 'bar' => 'bar (EN)', + 'choice' => '{0} choice 0 (EN)|{1} choice 1 (EN)|]1,Inf] choice inf (EN)', + )))) + ; + $loader + ->expects($this->at(2)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('es', array( + 'foobar' => 'foobar (ES)', + )))) + ; + $loader + ->expects($this->at(3)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('pt-PT', array( + 'foobarfoo' => 'foobarfoo (PT-PT)', + )))) + ; + $loader + ->expects($this->at(4)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('pt_BR', array( + 'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)', + )))) + ; + + return $loader; + } + + public function getTranslator($loader, $options = array()) + { + $translator = new Translator( + $loader, + new MessageSelector(), + $options + ); + + $translator->addLoader('loader', $loader); + $translator->addResource('loader', 'foo', 'fr'); + $translator->addResource('loader', 'foo', 'en'); + $translator->addResource('loader', 'foo', 'es'); + $translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese + $translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese + + return $translator; + } +} diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index 38b27fffb5464..8803c40f63d6e 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -13,6 +13,7 @@ use Symfony\Component\Translation\Loader\LoaderInterface; use Symfony\Component\Translation\Exception\NotFoundResourceException; +use Symfony\Component\Config\ConfigCache; /** * Translator. @@ -33,6 +34,14 @@ class Translator implements TranslatorInterface */ protected $locale; + /** + * @var array + */ + protected $options = array( + 'cache_dir' => null, + 'debug' => false, + ); + /** * @var array */ @@ -58,15 +67,23 @@ class Translator implements TranslatorInterface * * @param string $locale The locale * @param MessageSelector|null $selector The message selector for pluralization + * @param array $options An array of options * * @throws \InvalidArgumentException If a locale contains invalid characters * * @api */ - public function __construct($locale, MessageSelector $selector = null) + public function __construct($locale, MessageSelector $selector = null, array $options = array()) { $this->setLocale($locale); $this->selector = $selector ?: new MessageSelector(); + + // check option names + if ($diff = array_diff(array_keys($options), array_keys($this->options))) { + throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff))); + } + + $this->options = array_merge($this->options, $options); } /** @@ -282,7 +299,22 @@ public function getMessages($locale = null) return $messages; } + /* + * @param string $locale + */ protected function loadCatalogue($locale) + { + if (null === $this->options['cache_dir']) { + $this->initializeCatalogue($locale); + } else { + $this->initializeCacheCatalogue($locale); + } + } + + /** + * @param string $locale + */ + protected function initializeCatalogue($locale) { try { $this->doLoadCatalogue($locale); @@ -294,6 +326,75 @@ protected function loadCatalogue($locale) $this->loadFallbackCatalogues($locale); } + /** + * @param string $locale + */ + private function initializeCacheCatalogue($locale) + { + if (isset($this->catalogues[$locale])) { + return; + } + + if (null === $this->options['cache_dir']) { + $this->initialize(); + + return parent::loadCatalogue($locale); + } + + $cache = new ConfigCache($this->options['cache_dir'].'/catalogue.'.$locale.'.php', $this->options['debug']); + if (!$cache->isFresh()) { + $this->initialize(); + + parent::loadCatalogue($locale); + + $fallbackContent = ''; + $current = ''; + $replacementPattern = '/[^a-z0-9_]/i'; + foreach ($this->computeFallbackLocales($locale) as $fallback) { + $fallbackSuffix = ucfirst(preg_replace($replacementPattern, '_', $fallback)); + $currentSuffix = ucfirst(preg_replace($replacementPattern, '_', $current)); + + $fallbackContent .= sprintf(<<addFallbackCatalogue(\$catalogue%s); + + +EOF + , + $fallbackSuffix, + $fallback, + var_export($this->catalogues[$fallback]->all(), true), + $currentSuffix, + $fallbackSuffix + ); + $current = $fallback; + } + + $content = sprintf(<<catalogues[$locale]->all(), true), + $fallbackContent + ); + + $cache->write($content, $this->catalogues[$locale]->getResources()); + + return; + } + + $this->catalogues[$locale] = include $cache; + } + private function doLoadCatalogue($locale) { $this->catalogues[$locale] = new MessageCatalogue($locale); From 30fed6a62016fdec65508dd00b91dfadcb1056f8 Mon Sep 17 00:00:00 2001 From: Tristan Maindron Date: Fri, 11 Jul 2014 13:30:03 +0200 Subject: [PATCH 2/2] [Translation][Cache] Removed the options from the arguments of Translator Fixed phpdoc Aligned variables and description Removed enableCache and added cache setup in constructor Added tests for locales with . and @ with caching --- .../Translation/Translator.php | 14 +++- .../Component/Translation/CHANGELOG.md | 1 + .../Translation/Tests/TranslatorCacheTest.php | 84 ++++++++++++++++--- .../Component/Translation/Translator.php | 48 +++++------ 4 files changed, 111 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index 4751f46e0c945..996cbf8672e4a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -25,6 +25,11 @@ class Translator extends BaseTranslator protected $container; protected $loaderIds; + protected $options = array( + 'cache_dir' => null, + 'debug' => false, + ); + /** * Constructor. * @@ -45,7 +50,14 @@ public function __construct(ContainerInterface $container, MessageSelector $sele $this->container = $container; $this->loaderIds = $loaderIds; - parent::__construct(null, $selector, $options); + // check option names + if ($diff = array_diff(array_keys($options), array_keys($this->options))) { + throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff))); + } + + $this->options = array_merge($this->options, $options); + + parent::__construct(null, $selector, $this->options['cache_dir'], $this->options['debug']); } /** diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index e6b39eff7c54b..c0eeb7e94f15f 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -3,6 +3,7 @@ CHANGELOG 2.6.0 ----- + * added possibility to cache catalogues 2.5.0 diff --git a/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php b/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php index cf6da3d03c185..2a683fd7578bd 100644 --- a/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php +++ b/src/Symfony/Component/Translation/Tests/TranslatorCacheTest.php @@ -54,7 +54,7 @@ public function testTransWithoutCaching() { $translator = $this->getTranslator($this->getLoader()); $translator->setLocale('fr'); - $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin')); $this->assertEquals('foo (FR)', $translator->trans('foo')); $this->assertEquals('bar (EN)', $translator->trans('bar')); @@ -63,14 +63,16 @@ public function testTransWithoutCaching() $this->assertEquals('no translation', $translator->trans('no translation')); $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + $this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz')); + $this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax')); } public function testTransWithCaching() { // prime the cache - $translator = $this->getTranslator($this->getLoader(), array('cache_dir' => $this->tmpDir)); + $translator = $this->getTranslator($this->getLoader(), $this->tmpDir); $translator->setLocale('fr'); - $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin')); $this->assertEquals('foo (FR)', $translator->trans('foo')); $this->assertEquals('bar (EN)', $translator->trans('bar')); @@ -79,12 +81,14 @@ public function testTransWithCaching() $this->assertEquals('no translation', $translator->trans('no translation')); $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + $this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz')); + $this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax')); // do it another time as the cache is primed now $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); - $translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir)); + $translator = $this->getTranslator($loader, $this->tmpDir); $translator->setLocale('fr'); - $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR')); + $translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin')); $this->assertEquals('foo (FR)', $translator->trans('foo')); $this->assertEquals('bar (EN)', $translator->trans('bar')); @@ -93,6 +97,36 @@ public function testTransWithCaching() $this->assertEquals('no translation', $translator->trans('no translation')); $this->assertEquals('foobarfoo (PT-PT)', $translator->trans('foobarfoo')); $this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1)); + $this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz')); + $this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax')); + } + + public function testTransWithCachingWithInvalidLocale() + { + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $translator = $this->getTranslator($loader, $this->tmpDir, 'Symfony\Component\Translation\Tests\TranslatorWithInvalidLocale'); + + $translator->setLocale('invalid locale'); + + try { + $translator->trans('foo'); + $this->fail(); + } catch (\InvalidArgumentException $e) { + $this->assertFalse(file_exists($this->tmpDir.'/catalogue.invalid locale.php')); + } + } + + public function testLoadCatalogueWithCachingWithInvalidLocale() + { + $loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface'); + $translator = $this->getTranslator($loader, $this->tmpDir, 'Symfony\Component\Translation\Tests\TranslatorWithInvalidLocale'); + + try { + $translator->proxyLoadCatalogue('invalid locale'); + $this->fail(); + } catch (\InvalidArgumentException $e) { + $this->assertFalse(file_exists($this->tmpDir.'/catalogue.invalid locale.php')); + } } protected function getCatalogue($locale, $messages) @@ -145,17 +179,27 @@ protected function getLoader() 'other choice' => '{0} other choice 0 (PT-BR)|{1} other choice 1 (PT-BR)|]1,Inf] other choice inf (PT-BR)', )))) ; + $loader + ->expects($this->at(5)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('fr.UTF-8', array( + 'foobarbaz' => 'foobarbaz (fr.UTF-8)', + )))) + ; + $loader + ->expects($this->at(6)) + ->method('load') + ->will($this->returnValue($this->getCatalogue('sr@latin', array( + 'foobarbax' => 'foobarbax (sr@latin)', + )))) + ; return $loader; } - public function getTranslator($loader, $options = array()) + public function getTranslator($loader, $cacheDir = null, $translatorClass = '\Symfony\Component\Translation\Translator') { - $translator = new Translator( - $loader, - new MessageSelector(), - $options - ); + $translator = new $translatorClass('fr', new MessageSelector(), $cacheDir); $translator->addLoader('loader', $loader); $translator->addResource('loader', 'foo', 'fr'); @@ -163,7 +207,25 @@ public function getTranslator($loader, $options = array()) $translator->addResource('loader', 'foo', 'es'); $translator->addResource('loader', 'foo', 'pt-PT'); // European Portuguese $translator->addResource('loader', 'foo', 'pt_BR'); // Brazilian Portuguese + $translator->addResource('loader', 'foo', 'fr.UTF-8'); + $translator->addResource('loader', 'foo', 'sr@latin'); // Latin Serbian return $translator; } } + +class TranslatorWithInvalidLocale extends Translator +{ + /** + * {@inheritdoc} + */ + public function setLocale($locale) + { + $this->locale = $locale; + } + + public function proxyLoadCatalogue($locale) + { + $this->loadCatalogue($locale); + } +} diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index 8803c40f63d6e..9194cab6b89d1 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -34,14 +34,6 @@ class Translator implements TranslatorInterface */ protected $locale; - /** - * @var array - */ - protected $options = array( - 'cache_dir' => null, - 'debug' => false, - ); - /** * @var array */ @@ -62,28 +54,34 @@ class Translator implements TranslatorInterface */ private $selector; + /** + * @var string + */ + private $cacheDir; + + /** + * @var bool + */ + private $debug; + /** * Constructor. * * @param string $locale The locale * @param MessageSelector|null $selector The message selector for pluralization - * @param array $options An array of options + * @param string|null $cacheDir The directory to use for the cache + * @param bool $debug Use cache in debug mode ? * * @throws \InvalidArgumentException If a locale contains invalid characters * * @api */ - public function __construct($locale, MessageSelector $selector = null, array $options = array()) + public function __construct($locale, MessageSelector $selector = null, $cacheDir = null, $debug = false) { $this->setLocale($locale); $this->selector = $selector ?: new MessageSelector(); - - // check option names - if ($diff = array_diff(array_keys($options), array_keys($this->options))) { - throw new \InvalidArgumentException(sprintf('The Translator does not support the following options: \'%s\'.', implode('\', \'', $diff))); - } - - $this->options = array_merge($this->options, $options); + $this->cacheDir = $cacheDir; + $this->debug = $debug; } /** @@ -304,7 +302,7 @@ public function getMessages($locale = null) */ protected function loadCatalogue($locale) { - if (null === $this->options['cache_dir']) { + if (null === $this->cacheDir) { $this->initializeCatalogue($locale); } else { $this->initializeCacheCatalogue($locale); @@ -316,6 +314,8 @@ protected function loadCatalogue($locale) */ protected function initializeCatalogue($locale) { + $this->assertValidLocale($locale); + try { $this->doLoadCatalogue($locale); } catch (NotFoundResourceException $e) { @@ -331,21 +331,21 @@ protected function initializeCatalogue($locale) */ private function initializeCacheCatalogue($locale) { + if (isset($this->catalogues[$locale])) { return; } - if (null === $this->options['cache_dir']) { + if (null === $this->cacheDir) { $this->initialize(); - return parent::loadCatalogue($locale); + return $this->loadCatalogue($locale); } - $cache = new ConfigCache($this->options['cache_dir'].'/catalogue.'.$locale.'.php', $this->options['debug']); + $this->assertValidLocale($locale); + $cache = new ConfigCache($this->cacheDir.'/catalogue.'.$locale.'.php', $this->debug); if (!$cache->isFresh()) { - $this->initialize(); - - parent::loadCatalogue($locale); + $this->initializeCatalogue($locale); $fallbackContent = ''; $current = '';