<commit_before><?php namespace Barryvdh\TranslationManager;

use Illuminate\Database\Query\Expression;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Events\Dispatcher;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Symfony\Component\Finder\Finder;

/**
 * Class Manager
 * @package Barryvdh\TranslationManager
 */
class Manager
{

    /** @var \Illuminate\Foundation\Application */
    protected $app;
    /** @var \Illuminate\Filesystem\Filesystem */
    protected $files;
    /** @var \Illuminate\Events\Dispatcher */
    protected $events;

    protected $config;
    protected $imported;

    public
    function __construct(Application $app, Filesystem $files, Dispatcher $events)
    {
        $this->app = $app;
        $this->files = $files;
        $this->events = $events;

        // when instantiated from the service provider, config info is not yet loaded, trying to get it here
        // causes a problem since none of the keys are defined.
        $this->config = null;
    }

    protected
    function config()
    {
        return $this->config ?: $this->config = $this->app['config']['laravel-translation-manager::config'];
    }

    public
    function excludedPageEditGroup($group)
    {
        return in_array($group, $this->config()['exclude_page_edit_groups']);
    }

    /**
     * @param      $namespace string
     * @param      $group     string
     * @param      $key       string
     *
     * @param null $locale
     * @param bool $useLottery
     * @param bool $findOrNew
     *
     * @return \Barryvdh\TranslationManager\Models\Translation|null
     */
    public
    function missingKey($namespace, $group, $key, $locale = null, $useLottery = false, $findOrNew = false)
    {
        $group = $namespace && $namespace !== '*' ? $namespace . '::' . $group : $group;

        if (!in_array($group, $this->config()['exclude_groups']) && $this->config()['log_missing_keys'])
        {
            $lottery = 1;
            if ($useLottery)
            {
                $lottery = Session::get('laravel_translation_manager.lottery', '');
                if ($lottery === '')
                {
                    $lottery = rand(1, $this->config()['missing_keys_lottery']);
                    Session::put('laravel_translation_manager.lottery', $lottery);
                }
            }

            if ($lottery === 1)
            {
                if ($findOrNew)
                {
                    $translation = Translation::firstOrNew(array(
                        'locale' => $locale ?: $this->app['config']['app.locale'],
                        'group' => $group,<commit_msg>fix don't use lottery even if session has lottery value but lottery setting is 1 in config. otherwise no way to reset session value when config changes.<commit_after><?php namespace Barryvdh\TranslationManager;

use Illuminate\Database\Query\Expression;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Events\Dispatcher;
use Barryvdh\TranslationManager\Models\Translation;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;
use Symfony\Component\Finder\Finder;

/**
 * Class Manager
 * @package Barryvdh\TranslationManager
 */
class Manager
{

    /** @var \Illuminate\Foundation\Application */
    protected $app;
    /** @var \Illuminate\Filesystem\Filesystem */
    protected $files;
    /** @var \Illuminate\Events\Dispatcher */
    protected $events;

    protected $config;
    protected $imported;

    public
    function __construct(Application $app, Filesystem $files, Dispatcher $events)
    {
        $this->app = $app;
        $this->files = $files;
        $this->events = $events;

        // when instantiated from the service provider, config info is not yet loaded, trying to get it here
        // causes a problem since none of the keys are defined.
        $this->config = null;
    }

    protected
    function config()
    {
        return $this->config ?: $this->config = $this->app['config']['laravel-translation-manager::config'];
    }

    public
    function excludedPageEditGroup($group)
    {
        return in_array($group, $this->config()['exclude_page_edit_groups']);
    }

    /**
     * @param      $namespace string
     * @param      $group     string
     * @param      $key       string
     *
     * @param null $locale
     * @param bool $useLottery
     * @param bool $findOrNew
     *
     * @return \Barryvdh\TranslationManager\Models\Translation|null
     */
    public
    function missingKey($namespace, $group, $key, $locale = null, $useLottery = false, $findOrNew = false)
    {
        $group = $namespace && $namespace !== '*' ? $namespace . '::' . $group : $group;

        if (!in_array($group, $this->config()['exclude_groups']) && $this->config()['log_missing_keys'])
        {
            $lottery = 1;
            if ($useLottery && $this->config()['missing_keys_lottery'] !== 1)
            {
                $lottery = Session::get('laravel_translation_manager.lottery', '');
                if ($lottery === '')
                {
                    $lottery = rand(1, $this->config()['missing_keys_lottery']);
                    Session::put('laravel_translation_manager.lottery', $lottery);
                }
            }

            if ($lottery === 1)
            {
                if ($findOrNew)
                {
                    $translation = Translation::firstOrNew(array(
                        'locale' => $locale ?: $this->app['config']['app.locale'],
                        'group' => $group,
{'fraction_non_alphanumeric': 0.1327604349351105, 'fraction_numerical': 0.0014030164854437039, 'mean_word_length': 2.2927251732101617, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '3096175', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1574, 'n_words': 353}