Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame^] | 29 | /** |
| 30 | * List of translations |
| 31 | * |
| 32 | * @var array |
| 33 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 34 | var $language = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame^] | 35 | /** |
| 36 | * List of loaded language files |
| 37 | * |
| 38 | * @var array |
| 39 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | var $is_loaded = array(); |
| 41 | |
| 42 | /** |
| 43 | * Constructor |
| 44 | * |
| 45 | * @access public |
| 46 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 47 | function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 48 | { |
| 49 | log_message('debug', "Language Class Initialized"); |
| 50 | } |
| 51 | |
| 52 | // -------------------------------------------------------------------- |
| 53 | |
| 54 | /** |
| 55 | * Load a language file |
| 56 | * |
| 57 | * @access public |
| 58 | * @param mixed the name of the language file to be loaded. Can be an array |
| 59 | * @param string the language (english, etc.) |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame^] | 60 | * @param bool return loaded array of translations |
| 61 | * @param bool add suffix to $langfile |
| 62 | * @param string alternative path to look for language file |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | * @return mixed |
| 64 | */ |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 65 | function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 66 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 67 | $langfile = str_replace('.php', '', $langfile); |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 68 | |
| 69 | if ($add_suffix == TRUE) |
| 70 | { |
| 71 | $langfile = str_replace('_lang.', '', $langfile).'_lang'; |
| 72 | } |
| 73 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 74 | $langfile .= '.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | |
| 76 | if (in_array($langfile, $this->is_loaded, TRUE)) |
| 77 | { |
| 78 | return; |
| 79 | } |
| 80 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 81 | $config =& get_config(); |
| 82 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | if ($idiom == '') |
| 84 | { |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 85 | $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang; |
| 87 | } |
| 88 | |
| 89 | // Determine where the language file is and load it |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 90 | if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) |
| 91 | { |
| 92 | include($alt_path.'language/'.$idiom.'/'.$langfile); |
| 93 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 94 | else |
| 95 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 96 | $found = FALSE; |
| 97 | |
| 98 | foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 99 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 100 | if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) |
| 101 | { |
| 102 | include($package_path.'language/'.$idiom.'/'.$langfile); |
| 103 | $found = TRUE; |
| 104 | break; |
| 105 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 107 | |
| 108 | if ($found !== TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | { |
Derek Allard | ea9e4e0 | 2009-08-17 17:40:48 +0000 | [diff] [blame] | 110 | show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 114 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | if ( ! isset($lang)) |
| 116 | { |
| 117 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if ($return == TRUE) |
| 122 | { |
| 123 | return $lang; |
| 124 | } |
| 125 | |
| 126 | $this->is_loaded[] = $langfile; |
| 127 | $this->language = array_merge($this->language, $lang); |
| 128 | unset($lang); |
| 129 | |
| 130 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); |
| 131 | return TRUE; |
| 132 | } |
| 133 | |
| 134 | // -------------------------------------------------------------------- |
| 135 | |
| 136 | /** |
| 137 | * Fetch a single line of text from the language array |
| 138 | * |
| 139 | * @access public |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 140 | * @param string $line the language line |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 141 | * @return string |
| 142 | */ |
| 143 | function line($line = '') |
| 144 | { |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 145 | $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 146 | |
| 147 | // Because killer robots like unicorns! |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 148 | if ($value === FALSE) |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 149 | { |
| 150 | log_message('error', 'Could not find the language line "'.$line.'"'); |
| 151 | } |
| 152 | |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 153 | return $value; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | } |
| 157 | // END Language Class |
| 158 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 159 | /* End of file Lang.php */ |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 160 | /* Location: ./system/core/Lang.php */ |