<commit_before><?php
class i18n extends base {
    protected $__requirements = array("utils");
    public $languages;
    function addLanguage($language) {
        $language = str_replace(chr(0), "", strtolower($language));
        $language = preg_replace("/[^A-Za-z\_]/", "", $language);
        if(strlen($language) != 2 && strlen($language) != 5)
            $this->main->trigger_error("The language {$language} contains an invalid name");
        if(isset($this->languages[$language]))
            $this->main->trigger_error("The language {$language} is already loaded");
        if(is_file("languages".DS."{$language}.json")) {
            $this->languages[$language] = $this->main->utils->json_decode_file("languages".DS."{$language}.json");
        }else{
            $tmp = current(explode("_", $language));
            if(is_file("languages".DS."{$tmp}.json"))
                $this->languages[$language] = $this->main->utils->json_decode_file("languages".DS."{$tmp}.json");
            else
                $this->main->trigger_error("The file {$language}.json couldn't be found");
        }
        return true;
    }
    function removeLanguage($language) {
        unset($this->languages[$langunage]);
    }
    function setLang($lang) {
        if(!isset($this->languages[$language]))
            $this->main->trigger_error("The languages {$lang} isn't loaded");
        $this->lang = $lang;
    }
    function getTranslation($text, $args) {
        if(isset($this->languages[$this->lang]->$text))
            return $this->sprintf($this->languages[$this->lang]->$text, $args);
        else
            return $this->sprintf($text, $args);
    }
    function sprintf($text, $args = null) {
        if(is_array($args)) {
            foreach($args as $k => $v)
                $text = str_replace("%{$k}%", $v, $text);
        }elseif(is_string($args))
            $text = str_replace("%%%", $args, $text);
        return $text;
    }
}<commit_msg>Make the language class better<commit_after><?php
class i18n extends base {
	protected $__requirements = array("utils");
	public $language;
	function set($language) {
		$language = str_replace(chr(0), "", strtolower($language));
		$language = preg_replace("/[^A-Za-z\_]/", "", $language);
		if(strlen($language) != 2 && strlen($language) != 5)
			$this->main->trigger_error("The language {$language} contains an invalid name");
		if(is_file("languages".DS."{$language}.json")) {
			$this->language = $this->main->utils->json_decode_file("languages".DS."{$language}.json");
		}else{
			$tmp = current(explode("_", $language));
			if(is_file("languages".DS."{$tmp}.json"))
				$this->language = $this->main->utils->json_decode_file("languages".DS."{$tmp}.json");
			else
				$this->main->trigger_error("The file {$language}.json couldn't be found");
		}
		return true;
	}
	function getTranslation($text, $args) {
		if(isset($this->language->$text))
			return $this->sprintf($this->language->$text, $args);
		else
			return $this->sprintf($text, $args);
	}
	function sprintf($text, $args = null) {
		if(is_array($args)) {
			foreach($args as $k => $v)
				$text = str_replace("%{$k}%", $v, $text);
		}elseif(is_string($args))
			$text = str_replace("%%%", $args, $text);
		return $text;
	}
}
{'fraction_non_alphanumeric': 0.2046783625730994, 'fraction_numerical': 0.0030778701138811943, 'mean_word_length': 3.3507362784471217, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, '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': '6369024', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1017, 'n_words': 182}