<commit_before><?php

namespace Oro\Bundle\TranslationBundle\EventListener;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Oro\Bundle\TranslationBundle\Translation\Translator;
use Oro\Bundle\TranslationBundle\Translation\OrmTranslationResource;
use Oro\Bundle\TranslationBundle\Translation\DownloadableTranslationResource;
use Oro\Bundle\TranslationBundle\Translation\DynamicTranslationMetadataCache;

class RequestListener
{
    /**
     * @var Translator
     */
    protected $translator;

    /**
     * @var DynamicTranslationMetadataCache
     */
    protected $databaseTranslationMetadataCache;

    /**
     * @var DynamicTranslationMetadataCache
     */
    protected $downloadTranslationMetadataCache;

    /**
     * @var string[]
     */
    protected $registeredTranslationResources;

    /**
     * Constructor
     *
     * @param Translator                      $translator
     * @param DynamicTranslationMetadataCache $databaseTranslationMetadataCache
     * @param DynamicTranslationMetadataCache $downloadTranslationMetadataCache
     */
    public function __construct(
        Translator $translator,
        DynamicTranslationMetadataCache $databaseTranslationMetadataCache,
        DynamicTranslationMetadataCache $downloadTranslationMetadataCache
    ) {
        $this->translator                       = $translator;
        $this->databaseTranslationMetadataCache = $databaseTranslationMetadataCache;
        $this->downloadTranslationMetadataCache = $downloadTranslationMetadataCache;
        $this->registeredTranslationResources   = [];
    }

    /**
     * Register a database translation resources for the current request locale
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $locale = $this->translator->getLocale();
            // check if a resource has already registered to avoid duplicates
            if (!isset($this->registeredTranslationResources[$locale])) {
                $this->translator->addResource(
                    'oro_database_translation',
                    new OrmTranslationResource($locale, $this->databaseTranslationMetadataCache),
                    $locale,
                    'messages'
                );
                $this->translator->addResource(
                    'oro_database_translation',
                    new DownloadableTranslationResource($locale, $this->downloadTranslationMetadataCache),
                    $locale,
                    'messages'
                );
                $this->registeredTranslationResources[$locale] = true;
            }
        }
    }
}
<commit_msg>BAP-2193: Translations    - fix resource name and domain<commit_after><?php

namespace Oro\Bundle\TranslationBundle\EventListener;

use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Oro\Bundle\TranslationBundle\Translation\Translator;
use Oro\Bundle\TranslationBundle\Translation\OrmTranslationResource;
use Oro\Bundle\TranslationBundle\Translation\DownloadableTranslationResource;
use Oro\Bundle\TranslationBundle\Translation\DynamicTranslationMetadataCache;

class RequestListener
{
    /**
     * @var Translator
     */
    protected $translator;

    /**
     * @var DynamicTranslationMetadataCache
     */
    protected $databaseTranslationMetadataCache;

    /**
     * @var DynamicTranslationMetadataCache
     */
    protected $downloadTranslationMetadataCache;

    /**
     * @var string[]
     */
    protected $registeredTranslationResources;

    /**
     * Constructor
     *
     * @param Translator                      $translator
     * @param DynamicTranslationMetadataCache $databaseTranslationMetadataCache
     * @param DynamicTranslationMetadataCache $downloadTranslationMetadataCache
     */
    public function __construct(
        Translator $translator,
        DynamicTranslationMetadataCache $databaseTranslationMetadataCache,
        DynamicTranslationMetadataCache $downloadTranslationMetadataCache
    ) {
        $this->translator                       = $translator;
        $this->databaseTranslationMetadataCache = $databaseTranslationMetadataCache;
        $this->downloadTranslationMetadataCache = $downloadTranslationMetadataCache;
        $this->registeredTranslationResources   = [];
    }

    /**
     * Register a database translation resources for the current request locale
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $locale = $this->translator->getLocale();
            // check if a resource has already registered to avoid duplicates
            if (!isset($this->registeredTranslationResources[$locale])) {
                $this->translator->addResource(
                    'oro_database_translation',
                    new OrmTranslationResource($locale, $this->databaseTranslationMetadataCache),
                    $locale,
                    'messages'
                );
                $this->translator->addResource(
                    'oro_downloadable_translation',
                    new DownloadableTranslationResource($locale, $this->downloadTranslationMetadataCache),
                    $locale
                );
                $this->registeredTranslationResources[$locale] = true;
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.08385148338958963, 'fraction_numerical': 0.0007106057914372002, 'mean_word_length': 2.6416558861578268, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2769497', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1233, 'n_words': 223}