From 692c5486cdcfc05cd9dc6f348b09bc093b32eea8 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 2 Mar 2010 13:39:48 -0600 Subject: renamed class added ability to specify arbitrary path for language file (packages!) added ability to specify lang files that don't end in _lang, or to call file with _lang directly without it adding another _lang suffix --- system/core/Lang.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'system/core/Lang.php') diff --git a/system/core/Lang.php b/system/core/Lang.php index bbecab645..e071495b8 100644 --- a/system/core/Lang.php +++ b/system/core/Lang.php @@ -24,7 +24,7 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/language.html */ -class CI_Language { +class CI_Lang { var $language = array(); var $is_loaded = array(); @@ -34,7 +34,7 @@ class CI_Language { * * @access public */ - function CI_Language() + function CI_Lang() { log_message('debug', "Language Class Initialized"); } @@ -49,24 +49,36 @@ class CI_Language { * @param string the language (english, etc.) * @return mixed */ - function load($langfile = '', $idiom = '', $return = FALSE) + function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') { - $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; + $langfile = str_replace(EXT, '', $langfile); + + if ($add_suffix == TRUE) + { + $langfile = str_replace('_lang.', '', $langfile).'_lang'; + } + + $langfile .= EXT; if (in_array($langfile, $this->is_loaded, TRUE)) { return; } + $config =& get_config(); + if ($idiom == '') { - $CI =& get_instance(); - $deft_lang = $CI->config->item('language'); + $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; $idiom = ($deft_lang == '') ? 'english' : $deft_lang; } // Determine where the language file is and load it - if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) + if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) + { + include($alt_path.'language/'.$idiom.'/'.$langfile); + } + elseif (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) { include(APPPATH.'language/'.$idiom.'/'.$langfile); } @@ -82,6 +94,7 @@ class CI_Language { } } + if ( ! isset($lang)) { log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); @@ -119,5 +132,5 @@ class CI_Language { } // END Language Class -/* End of file Language.php */ -/* Location: ./system/core/Language.php */ \ No newline at end of file +/* End of file Lang.php */ +/* Location: ./system/core/Lang.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b