CI架構源碼閱讀---------Lang.php_PHP教程

來源:互聯網
上載者:User
[php] is_loaded和$this->language中去 * @param bool add suffix to $langfile 檔案是否添加尾碼 * @param string alternative path to look for language file 語言套件檔案的自訂路徑 * @return mixed */ function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { // langfile 檔案的.php 尾碼去掉 $langfile = str_replace('.php', '', $langfile); // 判斷需不需要添加尾碼如果需要 // 將_lang. 去掉並再langfile後面添加_lang if ($add_suffix == TRUE) { $langfile = str_replace('_lang.', '', $langfile).'_lang'; } // 為langfile添加.php尾碼 $langfile .= '.php'; // 判斷當前檔案是否被載入過 if (in_array($langfile, $this->is_loaded, TRUE)) { return; } // 擷取設定檔的資料 $config =& get_config(); // 如果要使用的語言為空白 // 那麼 我們將從$config中擷取 if ($idiom == '') { $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } // Determine where the language file is and load it // 在自訂路徑下尋找語言套件並載入 if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) { include($alt_path.'language/'.$idiom.'/'.$langfile); } else { // 如果自訂路徑下沒找到調用get_instance()->load->get_package_paths(TRUE) // 在包路徑下尋找 // get_package_paths這個函數在loader.php中 $found = FALSE; foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) { if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) { include($package_path.'language/'.$idiom.'/'.$langfile); $found = TRUE; break; } } // 如果還沒找到就只能報錯了 // if ($found !== TRUE) { show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); } } if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); return; } if ($return == TRUE) { return $lang; } $this->is_loaded[] = $langfile; $this->language = array_merge($this->language, $lang); unset($lang); log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); return TRUE; } // -------------------------------------------------------------------- /** * Fetch a single line of text from the language array * 擷取一行文本 * @access public * @param string $line the language line * @return string */ function line($line = '') { /* * $this->language 的樣子 * $lang['error_email_missing'] = "You must submit an email address"; * $lang['error_url_missing'] = "You must submit a URL"; * $lang['error_username_missing'] = "You must submit a username"; */ $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; // Because killer robots like unicorns! if ($value === FALSE) { log_message('error', 'Could not find the language line "'.$line.'"'); } return $value; } } // END Language Class /* End of file Lang.php */ /* Location: ./system/core/Lang.php */

http://www.bkjia.com/PHPjc/477660.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477660.htmlTechArticle[php] ?php if ( ! defined(BASEPATH)) exit(No direct script access allowed); /** * CodeIgniter * * An open source application development framework for PHP 5.1.6 or newer * * @packag...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.