admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Language Class |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Libraries |
| 23 | * @category Language |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.codeigniter.com/user_guide/libraries/language.html |
| 26 | */ |
| 27 | class CI_Language { |
| 28 | |
| 29 | var $language = array(); |
| 30 | var $is_loaded = array(); |
| 31 | |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @access public |
| 36 | */ |
| 37 | function CI_Language() |
| 38 | { |
| 39 | log_message('debug', "Language Class Initialized"); |
| 40 | } |
| 41 | // END CI_Language() |
| 42 | |
| 43 | // -------------------------------------------------------------------- |
| 44 | |
| 45 | /** |
| 46 | * Load a language file |
| 47 | * |
| 48 | * @access public |
| 49 | * @param mixed the name of the language file to be loaded. Can be an array |
| 50 | * @param string the language (english, etc.) |
| 51 | * @return void |
| 52 | */ |
| 53 | function load($langfile = '', $idiom = '', $return = FALSE) |
| 54 | { |
| 55 | $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; |
| 56 | |
| 57 | if (in_array($langfile, $this->is_loaded)) |
| 58 | { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ($idiom == '') |
| 63 | { |
| 64 | $obj =& get_instance(); |
| 65 | $deft_lang = $obj->config->item('language'); |
| 66 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang; |
| 67 | } |
| 68 | |
admin | d183cb5 | 2006-09-20 21:06:32 +0000 | [diff] [blame] | 69 | // Determine where the language file is and load it |
| 70 | |
| 71 | if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 72 | { |
admin | d183cb5 | 2006-09-20 21:06:32 +0000 | [diff] [blame] | 73 | include_once(APPPATH.'language/'.$idiom.'/'.$langfile); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) |
| 78 | { |
| 79 | include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | show_error('Unable to load the requested language file: language/'.$langfile); |
| 84 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 85 | } |
| 86 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 87 | |
| 88 | if ( ! isset($lang)) |
| 89 | { |
| 90 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | if ($return == TRUE) |
| 95 | { |
| 96 | return $lang; |
| 97 | } |
| 98 | |
| 99 | $this->is_loaded[] = $langfile; |
| 100 | $this->language = array_merge($this->language, $lang); |
| 101 | unset($lang); |
| 102 | |
| 103 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); |
| 104 | return TRUE; |
| 105 | } |
| 106 | // END load() |
| 107 | |
| 108 | // -------------------------------------------------------------------- |
| 109 | |
| 110 | /** |
| 111 | * Fetch a single line of text from the language array |
| 112 | * |
| 113 | * @access public |
| 114 | * @param string the language line |
| 115 | * @return string |
| 116 | */ |
| 117 | function line($line = '') |
| 118 | { |
| 119 | return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
| 120 | } |
| 121 | // END line() |
| 122 | |
| 123 | } |
| 124 | // END Language Class |
| 125 | ?> |