Kdyby\Translation\CatalogueCompiler::compile PHP Method

compile() public method

public compile ( Translator $translator, array &$availableCatalogues, string $locale ) : Symfony\Component\Translation\MessageCatalogueInterface | null
$translator Translator
$availableCatalogues array
$locale string
return Symfony\Component\Translation\MessageCatalogueInterface | null
    public function compile(Translator $translator, array &$availableCatalogues, $locale)
    {
        if (empty($locale)) {
            throw new InvalidArgumentException("Invalid locale.");
        }
        if (isset($availableCatalogues[$locale])) {
            return $availableCatalogues;
        }
        $cacheKey = [$locale, $translator->getFallbackLocales()];
        $storage = $this->cache->getStorage();
        if (!$storage instanceof Kdyby\Translation\Caching\PhpFileStorage) {
            if (($messages = $this->cache->load($cacheKey)) !== NULL) {
                $availableCatalogues[$locale] = new MessageCatalogue($locale, $messages);
                return $availableCatalogues;
            }
            $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale);
            $this->cache->save($cacheKey, $availableCatalogues[$locale]->all());
            return $availableCatalogues;
        }
        $storage->hint = $locale;
        $cached = $compiled = $this->cache->load($cacheKey);
        if ($compiled === NULL) {
            $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale);
            $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale));
            $cached = $this->cache->load($cacheKey);
        }
        $availableCatalogues[$locale] = self::load($cached['file']);
        return $availableCatalogues;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function loadCatalogue($locale)
 {
     if (empty($locale)) {
         throw new InvalidArgumentException("Invalid locale.");
     }
     if (isset($this->catalogues[$locale])) {
         return;
     }
     $this->catalogues = $this->catalogueCompiler->compile($this, $this->catalogues, $locale);
 }