<commit_before><?php
namespace mii\i18n;


use mii\web\Exception;

class Simple {

    protected $language;

    protected $base_path;

    protected $messages;

    public function __construct($config = []) {
        foreach($config as $key => $value) {
            $this->$key = $value;
        }

        if($this->base_path) {
            $this->base_path = \Mii::resolve($this->base_path);
        } else {
            $this->base_path = path('app').'/messages';
        }

        if($this->language === null) {
            $this->language = \Mii::$app->language;
        }

    }

    private function load() {

        if(!is_file($this->base_path.'/'.$this->language.'.php')) {
            throw new Exception();
        }

        $this->messages = require($this->base_path.'/'.$this->language.'.php');
    }


    public function translate($string) {
        if($this->messages === null)
            $this->load();


        return isset($this->messages[$string]) ? $this->messages[$string] : $string;
    }

}

<commit_msg>configurable i18n and message files searching improvement<commit_after><?php
namespace mii\i18n;


use mii\web\Exception;

class Simple {

    protected $language;

    protected $base_path;

    protected $messages;

    public function __construct($config = []) {
       $this->init($config);

    }

    public function init($config) {
        foreach($config as $key => $value) {
            $this->$key = $value;
        }

        if($this->base_path) {
            $this->base_path = \Mii::resolve($this->base_path);
        } else {
            $this->base_path = path('app').'/messages';
        }

        if($this->language === null) {
            $this->language = \Mii::$app->language;
        }
    }

    private function load() {

        if(!is_file($this->base_path.'/'.$this->language.'.php')) {

            list($lang, $country) = explode('-', $this->language);

            if(!is_file($this->base_path.'/'.$lang.'.php')) {
                throw new Exception();
            } else {
                $this->messages = require($this->base_path.'/'.$lang.'.php');
            }
        } else {
            $this->messages = require($this->base_path.'/'.$this->language.'.php');
        }
    }


    public function translate($string) {
        if($this->messages === null)
            $this->load();


        return isset($this->messages[$string]) ? $this->messages[$string] : $string;
    }

}


{'fraction_non_alphanumeric': 0.18092909535452323, 'fraction_numerical': 0.0024449877750611247, 'mean_word_length': 1.9975579975579976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 44, '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': '2054715', 'n_tokens_mistral': 754, 'n_tokens_neox': 725, 'n_words': 121}