<commit_before><?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author <NAME> <<EMAIL>>, 2013
 * @license The MIT License, http://opensource.org/licenses/MIT
 */

class Core_Lang extends MX_Lang {

    protected $config;

    protected $common_module_extender;

    public function __construct() {

        parent::__construct();

        $this->config = load_class('Config', 'core');
    }

    /**
     * Fetches a single line of text from the language array
     *
     * @param       string          $line           Language line key
     * @parap       string|array    $param          String or array of strings to be inserted at placeholders like %s, %d, etc.
     * @param       bool            $log_errors     Whether to log an error message if the line is not found
     * @return      string                          Translation
     */
    public function line($line, $param = NULL, $log_errors = TRUE) {

        $line = (string) $line;

        if (is_bool($param)) {

            // Backward compatibility, the parent method line()
            // does not contain $param parameter.
            $log_errors = $param;
            $param = '';

        } elseif (!is_array($param)) {

            $param = (string) $param;
        }

        $log_errors = (bool) $log_errors;

        if (!isset($this->language[$line])) {

            $value = FALSE;

        } else {

            $value = $this->language[$line];
            $line_has_parameters = strpos($value, '%') !== false;

            if (is_array($param) && !empty($param)) {

                if (!$line_has_parameters) {
                    // Prepend missing parameters.
                    $value = str_repeat('%s', count($param)).$value;
                }

                $value = @ vsprintf($value, $param);

            } else {

                if (!$line_has_parameters && $param != '') {
                    // Prepend the missing parameter.
                    $value = '%s'.$value;
                }

                $value = sprintf($value, $param);
            }
        }

        if ($value === FALSE && $log_errors) {

            log_message('error', 'Could not find the language line "'.$line.'"');
        }

        return $value;
    }

    // --------------------------------------------------------------------

    /**
     * i18n tag parser.
     * @param       string      $string     The input HTML content with i18n tags.
     * @return      string                  The parsed content as a result.
     * @link http://devzone.zend.com/1441/zend-framework-and-translation/
     */
    public function parse_i18n($string)
    {
        if (strlen($string) == 0)
        {
            return '';
        }

        $delimiter_start = '<i18n>';
        $delimiter_end = '</i18n>';
        $replacement_attr = 'replacement';
        $replacement_attr_delimiter = ',';

        $delimiter_start_length = strlen($delimiter_start);
        $delimiter_end_length = strlen($delimiter_end);

        $delimiter_begin = substr($delimiter_start, 0, -1);

        $offset = 0;

        while (($pos_start = strpos($string, $delimiter_begin, $offset)) !== false)
        {
            $offset = $pos_start + $delimiter_start_length;

            // Check for an tag ending '>'.<commit_msg>Suppressing an error.<commit_after><?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * @author <NAME> <<EMAIL>>, 2013
 * @license The MIT License, http://opensource.org/licenses/MIT
 */

class Core_Lang extends MX_Lang {

    protected $config;

    protected $common_module_extender;

    public function __construct() {

        parent::__construct();

        $this->config = load_class('Config', 'core');
    }

    /**
     * Fetches a single line of text from the language array
     *
     * @param       string          $line           Language line key
     * @parap       string|array    $param          String or array of strings to be inserted at placeholders like %s, %d, etc.
     * @param       bool            $log_errors     Whether to log an error message if the line is not found
     * @return      string                          Translation
     */
    public function line($line, $param = NULL, $log_errors = TRUE) {

        $line = (string) $line;

        if (is_bool($param)) {

            // Backward compatibility, the parent method line()
            // does not contain $param parameter.
            $log_errors = $param;
            $param = '';

        } elseif (!is_array($param)) {

            $param = (string) $param;
        }

        $log_errors = (bool) $log_errors;

        if (!isset($this->language[$line])) {

            $value = FALSE;

        } else {

            $value = $this->language[$line];
            $line_has_parameters = strpos($value, '%') !== false;

            if (is_array($param) && !empty($param)) {

                if (!$line_has_parameters) {
                    // Prepend missing parameters.
                    $value = str_repeat('%s', count($param)).$value;
                }

                $value = @ vsprintf($value, $param);

            } else {

                if (!$line_has_parameters && $param != '') {
                    // Prepend the missing parameter.
                    $value = '%s'.$value;
                }

                $value = sprintf($value, $param);
            }
        }

        if ($value === FALSE && $log_errors) {

            log_message('error', 'Could not find the language line "'.$line.'"');
        }

        return $value;
    }

    // --------------------------------------------------------------------

    /**
     * i18n tag parser.
     * @param       string      $string     The input HTML content with i18n tags.
     * @return      string                  The parsed content as a result.
     * @link http://devzone.zend.com/1441/zend-framework-and-translation/
     */
    public function parse_i18n($string)
    {
        if (strlen($string) == 0)
        {
            return '';
        }

        $delimiter_start = '<i18n>';
        $delimiter_end = '</i18n>';
        $replacement_attr = 'replacement';
        $replacement_attr_delimiter = ',';

        $delimiter_start_length = strlen($delimiter_start);
        $delimiter_end_length = strlen($delimiter_end);

        $delimiter_begin = substr($delimiter_start, 0, -1);

        $offset = 0;

        while (($pos_start = @ strpos($string, $delimiter_begin, $offset)) !== false)
        {
            $offset = $pos_start + $delimiter_start_length;

            // Check for an tag ending '>'.
{'fraction_non_alphanumeric': 0.14773413897280968, 'fraction_numerical': 0.006646525679758308, 'mean_word_length': 1.5893625342197888, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '5609760', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1768, 'n_words': 460}