Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author ExpressionEngine Dev Team |
Greg Aker | 0711dc8 | 2011-01-05 10:49:40 -0600 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html |
| 11 | * @link http://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 ExpressionEngine Dev Team |
| 25 | * @link http://codeigniter.com/user_guide/libraries/language.html |
| 26 | */ |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 27 | class CI_Lang { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
| 29 | var $language = array(); |
| 30 | var $is_loaded = array(); |
| 31 | |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @access public |
| 36 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 37 | function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | { |
| 39 | log_message('debug', "Language Class Initialized"); |
| 40 | } |
| 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 mixed |
| 51 | */ |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 52 | function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | { |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 54 | $langfile = str_replace(EXT, '', $langfile); |
| 55 | |
| 56 | if ($add_suffix == TRUE) |
| 57 | { |
| 58 | $langfile = str_replace('_lang.', '', $langfile).'_lang'; |
| 59 | } |
| 60 | |
| 61 | $langfile .= EXT; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | |
| 63 | if (in_array($langfile, $this->is_loaded, TRUE)) |
| 64 | { |
| 65 | return; |
| 66 | } |
| 67 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 68 | $config =& get_config(); |
| 69 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 70 | if ($idiom == '') |
| 71 | { |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 72 | $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang; |
| 74 | } |
| 75 | |
| 76 | // Determine where the language file is and load it |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 77 | if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) |
| 78 | { |
| 79 | include($alt_path.'language/'.$idiom.'/'.$langfile); |
| 80 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 81 | else |
| 82 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 83 | $found = FALSE; |
| 84 | |
| 85 | foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 87 | if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) |
| 88 | { |
| 89 | include($package_path.'language/'.$idiom.'/'.$langfile); |
| 90 | $found = TRUE; |
| 91 | break; |
| 92 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 94 | |
| 95 | if ($found !== TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | { |
Derek Allard | ea9e4e0 | 2009-08-17 17:40:48 +0000 | [diff] [blame] | 97 | show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 101 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | if ( ! isset($lang)) |
| 103 | { |
| 104 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if ($return == TRUE) |
| 109 | { |
| 110 | return $lang; |
| 111 | } |
| 112 | |
| 113 | $this->is_loaded[] = $langfile; |
| 114 | $this->language = array_merge($this->language, $lang); |
| 115 | unset($lang); |
| 116 | |
| 117 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); |
| 118 | return TRUE; |
| 119 | } |
| 120 | |
| 121 | // -------------------------------------------------------------------- |
| 122 | |
| 123 | /** |
| 124 | * Fetch a single line of text from the language array |
| 125 | * |
| 126 | * @access public |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 127 | * @param string $line the language line |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | * @return string |
| 129 | */ |
| 130 | function line($line = '') |
| 131 | { |
| 132 | $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame^] | 133 | |
| 134 | // Because killer robots like unicorns! |
| 135 | if ($line === FALSE) |
| 136 | { |
| 137 | log_message('error', 'Could not find the language line "'.$line.'"'); |
| 138 | } |
| 139 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | return $line; |
| 141 | } |
| 142 | |
| 143 | } |
| 144 | // END Language Class |
| 145 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 146 | /* End of file Lang.php */ |
| 147 | /* Location: ./system/core/Lang.php */ |