Language.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2008, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * Language Class
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Libraries
00023  * @category    Language
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/libraries/language.html
00026  */
00027 class CI_Language {
00028 
00029         var $language   = array();
00030         var $is_loaded  = array();
00031 
00032         /**
00033          * Constructor
00034          *
00035          * @access      public
00036          */     
00037         function CI_Language()
00038         {
00039                 log_message('debug', "Language Class Initialized");
00040         }
00041         
00042         // --------------------------------------------------------------------
00043         
00044         /**
00045          * Load a language file
00046          *
00047          * @access      public
00048          * @param       mixed   the name of the language file to be loaded. Can be an array
00049          * @param       string  the language (english, etc.)
00050          * @return      void
00051          */
00052         function load($langfile = '', $idiom = '', $return = FALSE)
00053         {       
00054                 $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;
00055                 
00056                 if (in_array($langfile, $this->is_loaded, TRUE))
00057                 {
00058                         return;
00059                 }
00060                 
00061                 if ($idiom == '')
00062                 {
00063                         $CI =& get_instance();
00064                         $deft_lang = $CI->config->item('language');
00065                         $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
00066                 }
00067         
00068                 // Determine where the language file is and load it
00069                 if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile))
00070                 {
00071                         include(APPPATH.'language/'.$idiom.'/'.$langfile);
00072                 }
00073                 else
00074                 {               
00075                         if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile))
00076                         {
00077                                 include(BASEPATH.'language/'.$idiom.'/'.$langfile);
00078                         }
00079                         else
00080                         {
00081                                 show_error('Unable to load the requested language file: language/'.$langfile);
00082                         }
00083                 }
00084 
00085                 
00086                 if ( ! isset($lang))
00087                 {
00088                         log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
00089                         return;
00090                 }
00091                 
00092                 if ($return == TRUE)
00093                 {
00094                         return $lang;
00095                 }
00096                 
00097                 $this->is_loaded[] = $langfile;
00098                 $this->language = array_merge($this->language, $lang);
00099                 unset($lang);
00100                 
00101                 log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
00102                 return TRUE;
00103         }
00104         
00105         // --------------------------------------------------------------------
00106         
00107         /**
00108          * Fetch a single line of text from the language array
00109          *
00110          * @access      public
00111          * @param       string  $line   the language line
00112          * @return      string
00113          */
00114         function line($line = '')
00115         {
00116                 $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
00117                 return $line;
00118         }
00119 
00120 }
00121 // END Language Class
00122 
00123 /* End of file Language.php */
00124 /* Location: ./system/libraries/Language.php */