<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
// ------------------------------------------------------------------------
/**
* Language Class
* 语言类
* @package CodeIgniter
* @subpackage Libraries
* @category Language
* @author ExpressionEngine Dev Team
* @link http://codeigniter.com/user_guide/libraries/language.html
*/
class CI_Lang {
/**
* List of translations
* 翻译列表
* @var array
*/
var $language = array();
/**
* List of loaded language files
* 加载的语言文件列表
* @var array
*/
var $is_loaded = array();
/**
* Constructor
*
* @access public
*/
function __construct()
{
log_message('debug', "Language Class Initialized 语言类初始化");
}
// --------------------------------------------------------------------
/**
* Load a language file
* 加载语言文件
* @access public
* @param mixed the name of the language file to be loaded. Can be an array
* 语言文件的名称被载入。可以是一个数组
* @param string the language (english, etc.)
* @param bool return loaded array of translations 返回翻译加载阵列
* @param bool add suffix to $langfile 增加至$ langfile的后缀
* @param string alternative path to look for language file 替代路径寻找语言文件
* @return mixed
*/
function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
//将语言文件中的.php后缀去掉
$langfile = str_replace('.php', '', $langfile);
//如果添加后后缀为真时
if ($add_suffix == TRUE)
{
//将$langfile里抽_lang.去掉,然后在后面在加上这个字会
$langfile = str_replace('_lang.', '', $langfile).'_lang';
}
//然后添加.php后缀,这添加来添加去的,干嘛呢>>>
$langfile .= '.php';
//如果该文件在已经加载的语言包数据中已经存在,就直接返回
if (in_array($langfile, $this->is_loaded, TRUE))
{
return;
}
$config =& get_config(); //配置文件对象
//
if ($idiom == '')
{
//如果没有设置默认的语言,那么设置为english
$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
{
$found = FALSE;
//get_instance() 是$CI对象
//$this->_ci_library_paths
//get_package_paths(true) 返回所有_ci_library_paths中的路径信息
//然后循环在这些目录里面查找语言文件
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);
}
}
//如果语言文件中没有$lang的话
if ( ! isset($lang))
{
log_message('error', 'Language file contains no data 语言文件不包含任何数据: language/'.$idiom.'/'.$langfile);
return;
}
//如果$return==true直接将语言文件内容返回
if ($return == TRUE)
{
return $lang;
}
//将该文件放入is_loaded数组中去
$this->is_loaded[] = $langfile;
//然后将language与$lang数组进行合并
$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 = '')
{
$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 */