public function rebuildCache($locale) { $cache = new ConfigCache($this->options['cache_dir'] . '/catalogue.' . $locale . '.php', $this->options['debug']); $this->initialize(); // one of the rare situations to "skip" to the grandparent implementation. \Symfony\Component\Translation\Translator::loadCatalogue($locale); $fallbackContent = ''; $current = ''; foreach ($this->computeFallbackLocales($locale) as $fallback) { $fallbackSuffix = ucfirst(str_replace('-', '_', $fallback)); $fallbackContent .= sprintf(<<<EOF \$catalogue%s = new MessageCatalogue('%s', %s); \$catalogue%s->addFallbackCatalogue(\$catalogue%s); EOF , $fallbackSuffix, $fallback, var_export($this->catalogues[$fallback]->all(), true), ucfirst(str_replace('-', '_', $current)), $fallbackSuffix); $current = $fallback; } $content = sprintf(<<<EOF <?php use Symfony\\Component\\Translation\\MessageCatalogue; \$catalogue = new MessageCatalogue('%s', %s); %s return \$catalogue; EOF , $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent); $cache->write($content, $this->catalogues[$locale]->getResources()); }
/** * @{inheritDoc} */ public function loadCatalogue($locale) { $cacheKey = sprintf('cog.localisation.translations1.%s', $locale); if (false === $this->_cacheEnabled or false === ($this->catalogues = $this->_container['cache']->fetch($cacheKey))) { $parser = $this->_container['reference_parser']; // Load translation files from modules foreach ($this->_container['module.loader']->getModules() as $moduleName) { $moduleName = str_replace('\\', $parser::SEPARATOR, $moduleName); $dir = 'cog://@' . $moduleName . $parser::MODULE_SEPARATOR . 'translations'; if (file_exists($dir)) { foreach ($this->_container['filesystem.finder']->in($dir) as $file) { $this->addResource('yml', $file->getPathname(), $file->getFilenameWithoutExtension()); } } } // Load application translation files $dir = $this->_container['app.loader']->getBaseDir() . 'translations'; if (file_exists($dir)) { foreach ($this->_container['filesystem.finder']->in($dir) as $file) { $this->addResource('yml', $file->getPathname(), $file->getFilenameWithoutExtension()); } } parent::loadCatalogue($locale); $this->_container['cache']->store($cacheKey, $this->catalogues); } }
/** * {@inheritdoc} */ protected function loadCatalogue($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(<<<EOF \$catalogue%s = new MessageCatalogue('%s', %s); \$catalogue%s->addFallbackCatalogue(\$catalogue%s); EOF , $fallbackSuffix, $fallback, var_export($this->catalogues[$fallback]->all(), true), $currentSuffix, $fallbackSuffix); $current = $fallback; } $content = sprintf(<<<EOF <?php use Symfony\\Component\\Translation\\MessageCatalogue; \$catalogue = new MessageCatalogue('%s', %s); %s return \$catalogue; EOF , $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent); $cache->write($content, $this->catalogues[$locale]->getResources()); return; } $this->catalogues[$locale] = (include $cache); }
/** * {@inheritdoc} */ protected function loadCatalogue($locale) { if (isset($this->catalogues[$locale])) { return; } if (null === $this->options['cache_dir']) { $this->initialize(); return parent::loadCatalogue($locale); } if ($this->needsReload($locale)) { $this->initialize(); parent::loadCatalogue($locale); $this->updateCache($locale); return; } $this->catalogues[$locale] = (include $this->getCacheFile($locale)); }
/** * {@inheritdoc} */ protected function loadCatalogue($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); $content = sprintf("<?php use Symfony\\Component\\Translation\\MessageCatalogue; return new MessageCatalogue('%s', %s);", $locale, var_export($this->catalogues[$locale]->all(), true)); $cache->write($content, $this->catalogues[$locale]->getResources()); return; } $this->catalogues[$locale] = (include $cache); }
/** * {@inheritdoc} */ protected function loadCatalogue($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 = ''; $fallback = $this->computeFallbackLocale($locale); if ($fallback && $fallback != $locale) { $fallbackContent = sprintf(<<<EOF \$catalogue->addFallbackCatalogue(new MessageCatalogue('%s', %s)); EOF , $fallback, var_export($this->catalogues[$fallback]->all(), true)); } $content = sprintf(<<<EOF <?php use Symfony\\Component\\Translation\\MessageCatalogue; \$catalogue = new MessageCatalogue('%s', %s); %s return \$catalogue; EOF , $locale, var_export($this->catalogues[$locale]->all(), true), $fallbackContent); $cache->write($content, $this->catalogues[$locale]->getResources()); return; } $this->catalogues[$locale] = (include $cache); }