<commit_before><?php

namespace Saxulum\Translation\Provider;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Translation\Translator;

class TranslationProvider
{
    public function register(\Pimple $container)
    {
        $container['translation_cache'] = null;

        $container['translation_paths'] = $container->share(function () {
            $paths = array();

            return $paths;
        });

        $container['translator'] = $container->share($container->extend('translator',
            function (Translator $translator) use ($container) {

                if (!is_null($container['translation_cache'])) {
                    if (!is_null($container['translation_cache']) && !is_dir($container['translation_cache'])) {
                        mkdir($container['translation_cache'], 0777, true);
                    }

                    $cacheFile = $container['translation_cache'] . '/saxulum-translation.php';
                    if ($container['debug'] || !file_exists($cacheFile)) {
                        file_put_contents(
                            $cacheFile,
                            '<?php return ' . var_export($container['translation_search'](), true) . ';'
                        );
                    }

                    $translationMap = require($cacheFile);
                } else {
                    $translationMap = $container['translation_search']();
                }

                $translator->addLoader('yaml', new YamlFileLoader());
                foreach ($translationMap as $translation) {
                    $translator->addResource('yaml', $translation['path'], $translation['locale'], $translation['domain']);
                }

                return $translator;
            }
        ));

        $container['translation_search'] = $container->protect(function () use ($container) {
            $translationMap = array();
            foreach ($container['translation_paths'] as $path) {
                foreach (Finder::create()->files()->name('*.yml')->in($path) as $file) {
                    /** @var SplFileInfo $file */
                    $domainAndLocale = explode('.', $file->getBasename('.yml'));<commit_msg>Avoid reloading from the written cache in debug mode<commit_after><?php

namespace Saxulum\Translation\Provider;

use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Translation\Translator;

class TranslationProvider
{
    public function register(\Pimple $container)
    {
        $container['translation_cache'] = null;

        $container['translation_paths'] = $container->share(function () {
            $paths = array();

            return $paths;
        });

        $container['translator'] = $container->share($container->extend('translator',
            function (Translator $translator) use ($container) {

                if (!is_null($container['translation_cache'])) {
                    if (!is_null($container['translation_cache']) && !is_dir($container['translation_cache'])) {
                        mkdir($container['translation_cache'], 0777, true);
                    }

                    $cacheFile = $container['translation_cache'] . '/saxulum-translation.php';
                    if ($container['debug'] || !file_exists($cacheFile)) {
                        $translationMap = $container['translation_search']();
                        file_put_contents(
                            $cacheFile,
                            '<?php return ' . var_export($translationMap, true) . ';'
                        );
                    } else {
                        $translationMap = require $cacheFile;
                    }
                } else {
                    $translationMap = $container['translation_search']();
                }

                $translator->addLoader('yaml', new YamlFileLoader());
                foreach ($translationMap as $translation) {
                    $translator->addResource('yaml', $translation['path'], $translation['locale'], $translation['domain']);
                }

                return $translator;
            }
        ));

        $container['translation_search'] = $container->protect(function () use ($container) {
            $translationMap = array();
            foreach ($container['translation_paths'] as $path) {
                foreach (Finder::create()->files()->name('*.yml')->in($path) as $file) {
                    /** @var SplFileInfo $file */
                    $domainAndLocale = explode('.', $file->getBasename('.yml'));
{'fraction_non_alphanumeric': 0.1394464398901331, 'fraction_numerical': 0.001690259877456159, 'mean_word_length': 1.9754871150219988, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4107048', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1093, 'n_words': 191}