<commit_before><?php namespace Wirelab\LanguageSwitcherPlugin\LanguageSwitcher\Command;

use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Exception;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;

class RenderLanguageSwitcher
{
    use DispatchesJobs;

    private $container_class;
    private $toggle_class;
    private $toggle_title;
    private $ul_class;
    private $li_class;
    private $a_class;
    private $type;

    public function __construct(String $type, Array $options)
    {
        $default_toggle_class = $type == 'li' ? 'dropdown' : 'btn btn-primary dropdown-toggle';

        $this->container_class    = isset($options['container_class'])    ? $options['container_class']    : 'dropdown';
        $this->toggle_class       = isset($options['toggle_class']) ? $options['toggle_class'] : $default_toggle_class;
        $this->toggle_title       = isset($options['toggle_title']) ? $options['toggle_title'] : false;
        $this->ul_class           = isset($options['ul_class'])     ? $options['ul_class']     : 'dropdown-menu';
        $this->li_class           = isset($options['li_class'])     ? $options['li_class']     : '';
        $this->a_class            = isset($options['a_class'])      ? $options['a_class']      : '';
        $this->type               = $type;
    }

    public function handle(
        SettingRepositoryInterface $settings,
        Request $request,
        Repository $config
    )
   {
        $type             = $this->type;
        $types            = [];
        $locales          = $settings->value('streams::enabled_locales'); // Get an array of all currently enables locales.
        $current_path     = $request->path(); // Get the current request path. For example /pages/some-page-title
        $current_locale   = $config->get('app.locale'); // Get the current request locale.
        $prefered_locale  = $request->server('HTTP_ACCEPT_LANGUAGE'); // Extract http_accept_lang from the request
        $prefered_locale  = strtolower(substr($prefered_locale, 0, strpos($prefered_locale, ','))); // Get the first prefered lang out of the string
        $prefered_enabled = in_array($prefered_locale, $locales); // Check if the prefered locale is enabled in pyro
        $prefered_url     = url()->locale($current_path,$prefered_locale);
        $toggle_title     = $this->toggle_title ? $this->toggle_title : $current_locale . " <span class='caret'></span>"; // If the user has passed a button title set it, else default to the currently enabled locale.
        $custom_title     = $this->toggle_title != false; // Check if the user has set a custom title. Used in building the ul of locales
        $views_dir        = File::directories('../addons')[0] . '/wirelab/language_switcher-plugin/resources/views'; // Get the dir within the addon dir

        foreach (File::allFiles($views_dir) as $file){
            // Use the names of the views as types
            $types[] = $file->getBaseName('.' . $file->getExtension());
        }

        if (!in_array($type, $types)) {
            throw new Exception("Unkown LanguageSwitcher type");
        }

        if(($key = array_search($current_locale, $locales)) !== false && !$custom_title) {
            // If the user has not set a button title we're going to use the currently enabled locale as title
            // here we unset it to prevent the locale from showing up both as a list item and title
            unset($locales[$key]);
        }
<commit_msg>fixed composer folder issue<commit_after><?php namespace Wirelab\LanguageSwitcherPlugin\LanguageSwitcher\Command;

use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Exception;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;

class RenderLanguageSwitcher
{
    use DispatchesJobs;

    private $container_class;
    private $toggle_class;
    private $toggle_title;
    private $ul_class;
    private $li_class;
    private $a_class;
    private $type;

    public function __construct(String $type, Array $options)
    {
        $default_toggle_class = $type == 'li' ? 'dropdown' : 'btn btn-primary dropdown-toggle';

        $this->container_class    = isset($options['container_class'])    ? $options['container_class']    : 'dropdown';
        $this->toggle_class       = isset($options['toggle_class']) ? $options['toggle_class'] : $default_toggle_class;
        $this->toggle_title       = isset($options['toggle_title']) ? $options['toggle_title'] : false;
        $this->ul_class           = isset($options['ul_class'])     ? $options['ul_class']     : 'dropdown-menu';
        $this->li_class           = isset($options['li_class'])     ? $options['li_class']     : '';
        $this->a_class            = isset($options['a_class'])      ? $options['a_class']      : '';
        $this->type               = $type;
    }

    public function handle(
        SettingRepositoryInterface $settings,
        Request $request,
        Repository $config
    )
   {
        $type             = $this->type;
        $types            = [];
        $locales          = $settings->value('streams::enabled_locales'); // Get an array of all currently enables locales.
        $current_path     = $request->path(); // Get the current request path. For example /pages/some-page-title
        $current_locale   = $config->get('app.locale'); // Get the current request locale.
        $prefered_locale  = $request->server('HTTP_ACCEPT_LANGUAGE'); // Extract http_accept_lang from the request
        $prefered_locale  = strtolower(substr($prefered_locale, 0, strpos($prefered_locale, ','))); // Get the first prefered lang out of the string
        $prefered_enabled = in_array($prefered_locale, $locales); // Check if the prefered locale is enabled in pyro
        $prefered_url     = url()->locale($current_path,$prefered_locale);
        $toggle_title     = $this->toggle_title ? $this->toggle_title : $current_locale . " <span class='caret'></span>"; // If the user has passed a button title set it, else default to the currently enabled locale.
        $custom_title     = $this->toggle_title != false; // Check if the user has set a custom title. Used in building the ul of locales

        if (file_exists('../core/wirelab')) {
            $views_dir = File::directories('../core/wirelab/language_switcher-plugin/resources/views'); // Get the dir within the addon dir
        } elseif(file_exists(File::directories('../addons')[0] . '/wirelab/language_switcher-plugin/resources/views')) {
            $views_dir = File::directories('../addons')[0] . '/wirelab/language_switcher-plugin/resources/views'; // Get the dir within the addon dir
        } else {
            throw new Exception("Couldn't find view folder.");
        }

        foreach (File::allFiles($views_dir) as $file){
            // Use the names of the views as types
            $types[] = $file->getBaseName('.' . $file->getExtension());
        }

        if (!in_array($type, $types)) {
            throw new Exception("Unkown LanguageSwitcher type.");
        }

        if(($key = array_search($current_locale, $locales)) !== false && !$custom_title) {
            // If the user has not set a button title we're going to use the currently enabled locale as title
            // here we unset it to prevent the locale from showing up both as a list item and title
            unset($locales[$key]);
        }

{'fraction_non_alphanumeric': 0.12812417784793476, 'fraction_numerical': 0.0006577216521967903, 'mean_word_length': 2.8282980866062437, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, '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': '5213547', 'n_tokens_mistral': 2123, 'n_tokens_neox': 2125, 'n_words': 545}