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. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Language Class |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 20 | * |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 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 | /** |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 33 | * Constructor |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 34 | * |
| 35 | * @access public |
| 36 | */ |
| 37 | function CI_Language() |
| 38 | { |
| 39 | log_message('debug', "Language Class Initialized"); |
| 40 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 41 | |
| 42 | // -------------------------------------------------------------------- |
| 43 | |
| 44 | /** |
| 45 | * Load a language file |
| 46 | * |
| 47 | * @access public |
| 48 | * @param mixed the name of the language file to be loaded. Can be an array |
| 49 | * @param string the language (english, etc.) |
| 50 | * @return void |
| 51 | */ |
| 52 | function load($langfile = '', $idiom = '', $return = FALSE) |
| 53 | { |
| 54 | $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT; |
| 55 | |
admin | ee54c11 | 2006-09-28 17:13:38 +0000 | [diff] [blame] | 56 | if (in_array($langfile, $this->is_loaded, TRUE)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 57 | { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | if ($idiom == '') |
| 62 | { |
admin | 88a8ad1 | 2006-10-07 03:16:32 +0000 | [diff] [blame] | 63 | $CI =& get_instance(); |
| 64 | $deft_lang = $CI->config->item('language'); |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 65 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang; |
| 66 | } |
| 67 | |
admin | d183cb5 | 2006-09-20 21:06:32 +0000 | [diff] [blame] | 68 | // Determine where the language file is and load it |
| 69 | |
| 70 | if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile)) |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 71 | { |
admin | d183cb5 | 2006-09-20 21:06:32 +0000 | [diff] [blame] | 72 | include_once(APPPATH.'language/'.$idiom.'/'.$langfile); |
| 73 | } |
| 74 | else |
| 75 | { |
| 76 | if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile)) |
| 77 | { |
| 78 | include_once(BASEPATH.'language/'.$idiom.'/'.$langfile); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | show_error('Unable to load the requested language file: language/'.$langfile); |
| 83 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 84 | } |
| 85 | |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 86 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 87 | if ( ! isset($lang)) |
| 88 | { |
| 89 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | if ($return == TRUE) |
| 94 | { |
| 95 | return $lang; |
| 96 | } |
| 97 | |
| 98 | $this->is_loaded[] = $langfile; |
| 99 | $this->language = array_merge($this->language, $lang); |
| 100 | unset($lang); |
| 101 | |
| 102 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); |
| 103 | return TRUE; |
| 104 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 105 | |
| 106 | // -------------------------------------------------------------------- |
| 107 | |
| 108 | /** |
| 109 | * Fetch a single line of text from the language array |
| 110 | * |
| 111 | * @access public |
| 112 | * @param string the language line |
| 113 | * @return string |
| 114 | */ |
| 115 | function line($line = '') |
| 116 | { |
| 117 | return ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
| 118 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 119 | |
| 120 | } |
| 121 | // END Language Class |
| 122 | ?> |