<commit_before><?php

namespace Kunstmaan\TranslatorBundle\Service\Translator;

use Kunstmaan\TranslatorBundle\Entity\TranslationDomain;
use Kunstmaan\TranslatorBundle\Entity\Translation;
use Kunstmaan\TranslatorBundle\Model\Translation\TranslationGroup;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Bundle\FrameworkBundle\Translation\Translator as SymfonyTranslator;


class Translator extends SymfonyTranslator
{

    private $stasher;
    private $resourceCacher;

    public function addDatabaseResources()
    {
        if($this->addResourcesFromCacher() === false) {
            $this->addResourcesFromStasherAndCache();
        }
    }

    public function addResourcesFromCacher()
    {
        $resources = $this->resourceCacher->getCachedResources(false);

        if($resources !== false) {
            $this->addResources($resources);
            return true;
        }

        return false;
    }

    public function addResourcesFromStasherAndCache()
    {
        $resources = $this->stasher->getTranslationDomainsByLocale();
        $this->addResources($resources);
        $this->resourceCacher->cacheResources($resources);
    }

    public function addResources($resources)
    {
        foreach ($resources as $resource) {
            $this->addResource('database', 'DB', $resource['locale'], $resource['name']);
         }
    }

    public function setStasher($stasher)
    {
        $this->stasher = $stasher;
    }

    public function setResourceCacher($resourceCacher)
    {
        $this->resourceCacher = $resourceCacher;
    }
}<commit_msg>No cached catalogues when running debug=true<commit_after><?php

namespace Kunstmaan\TranslatorBundle\Service\Translator;

use Kunstmaan\TranslatorBundle\Entity\TranslationDomain;
use Kunstmaan\TranslatorBundle\Entity\Translation;
use Kunstmaan\TranslatorBundle\Model\Translation\TranslationGroup;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Bundle\FrameworkBundle\Translation\Translator as SymfonyTranslator;


class Translator extends SymfonyTranslator
{

    private $stasher;
    private $resourceCacher;

    public function addDatabaseResources()
    {
        if($this->addResourcesFromCacher() === false) {
            $this->addResourcesFromStasherAndCache();
        }
    }

    public function addResourcesFromCacher()
    {
        $resources = $this->resourceCacher->getCachedResources(false);

        if($resources !== false) {
            $this->addResources($resources);
            return true;
        }

        return false;
    }

    public function addResourcesFromStasherAndCache()
    {
        $resources = $this->stasher->getTranslationDomainsByLocale();
        $this->addResources($resources);
        $this->resourceCacher->cacheResources($resources);
    }

    public function addResources($resources)
    {
        foreach ($resources as $resource) {
            $this->addResource('database', 'DB', $resource['locale'], $resource['name']);
         }
    }

    /**
     * {@inheritdoc}
     */
    protected function loadCatalogue($locale)
    {

        if($this->options['debug'] === true) {
            $this->options['cache_dir'] = null; // disable caching for debug
        }

        return parent::loadCatalogue($locale);
    }

    public function setStasher($stasher)
    {
        $this->stasher = $stasher;
    }

    public function setResourceCacher($resourceCacher)
    {
        $this->resourceCacher = $resourceCacher;
    }
}
{'fraction_non_alphanumeric': 0.11237169097784981, 'fraction_numerical': 0.0, 'mean_word_length': 3.2612197928653623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6720041', 'n_tokens_mistral': 1033, 'n_tokens_neox': 1017, 'n_words': 165}