<commit_before><?php
namespace Grav\Common;

/**
 * Contain some useful language functions
 */
class Language
{
    protected $languages = [];
    protected $page_extensions = [];
    protected $default;
    protected $active;
    protected $enabled = true;

    public function __construct(Grav $grav)
    {
        $this->languages = $grav['config']->get('system.languages.supported', []);
        $this->default = reset($this->languages);

        if (empty($this->languages)) {
            $this->enabled = false;
        }

    }

    public function enabled()
    {
        return $this->enabled;
    }

    public function getLanguages()
    {
        return $this->languages;
    }

    public function setLanguages($langs)
    {
        $this->languages = $langs;
    }

    public function getAvailable()
    {
        return implode('|', $this->languages);
    }

    public function getDefault()
    {
        return $this->default;
    }

    public function setDefault($lang)
    {
        if ($this->validate($lang)) {
            $this->default = $lang;
            return $lang;
        }
        return false;
    }

    public function getActive()
    {
        return $this->active;
    }

    public function setActive($lang)
    {
        if ($this->validate($lang)) {
            $this->active = $lang;
            return $lang;
        }
        return false;
    }

    public function setActiveFromUri($uri)
    {
        $regex = '/(\/('.$this->getAvailable().')).*/';
        // if languages set

        if ($this->enabled()) {
            if (preg_match($regex, $uri, $matches)) {
                $this->active = $matches[2];
                $uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1);
            } else {
                $this->active = null;
            }
        }
        return $uri;
    }

    public function setValidPageExtensions($extensions)
    {
        $this->page_extensions = (array) $extensions;
    }

    public function getValidPageExtensions()
    {
        if (empty($this->page_extensions)) {

            if ($this->enabled()) {
                $valid_lang_extensions = [];
                foreach ($this->languages as $lang) {
                    $valid_lang_extensions[] = '.'.$lang.CONTENT_EXT;
                }


                if ($this->active) {
                    $active_extension = '.'.$this->active.CONTENT_EXT;
                    $key = array_search($active_extension, $valid_lang_extensions);
                    unset($valid_lang_extensions[$key]);
                    array_unshift($valid_lang_extensions, $active_extension);
                }<commit_msg>removed unused method for now<commit_after><?php
namespace Grav\Common;

/**
 * Contain some useful language functions
 */
class Language
{
    protected $languages = [];
    protected $page_extensions = [];
    protected $default;
    protected $active;
    protected $enabled = true;

    public function __construct(Grav $grav)
    {
        $this->languages = $grav['config']->get('system.languages.supported', []);
        $this->default = reset($this->languages);

        if (empty($this->languages)) {
            $this->enabled = false;
        }

    }

    public function enabled()
    {
        return $this->enabled;
    }

    public function getLanguages()
    {
        return $this->languages;
    }

    public function setLanguages($langs)
    {
        $this->languages = $langs;
    }

    public function getAvailable()
    {
        return implode('|', $this->languages);
    }

    public function getDefault()
    {
        return $this->default;
    }

    public function setDefault($lang)
    {
        if ($this->validate($lang)) {
            $this->default = $lang;
            return $lang;
        }
        return false;
    }

    public function getActive()
    {
        return $this->active;
    }

    public function setActive($lang)
    {
        if ($this->validate($lang)) {
            $this->active = $lang;
            return $lang;
        }
        return false;
    }

    public function setActiveFromUri($uri)
    {
        $regex = '/(\/('.$this->getAvailable().')).*/';
        // if languages set

        if ($this->enabled()) {
            if (preg_match($regex, $uri, $matches)) {
                $this->active = $matches[2];
                $uri = preg_replace("/\\".$matches[1]."/", '', $matches[0], 1);
            } else {
                $this->active = null;
            }
        }
        return $uri;
    }

    public function getValidPageExtensions()
    {
        if (empty($this->page_extensions)) {
            if ($this->enabled()) {
                $valid_lang_extensions = [];
                foreach ($this->languages as $lang) {
                    $valid_lang_extensions[] = '.'.$lang.CONTENT_EXT;
                }

                if ($this->active) {
                    $active_extension = '.'.$this->active.CONTENT_EXT;
                    $key = array_search($active_extension, $valid_lang_extensions);
                    unset($valid_lang_extensions[$key]);
                    array_unshift($valid_lang_extensions, $active_extension);
                }
{'fraction_non_alphanumeric': 0.14208598419124735, 'fraction_numerical': 0.001542317331791016, 'mean_word_length': 1.7362869198312236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, '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': '3293719', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1410, 'n_words': 280}