Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [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 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Language Class |
| 30 | * |
| 31 | * @package CodeIgniter |
| 32 | * @subpackage Libraries |
| 33 | * @category Language |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/libraries/language.html |
| 36 | */ |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 37 | class CI_Lang { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 39 | /** |
| 40 | * List of translations |
| 41 | * |
| 42 | * @var array |
| 43 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 44 | public $language = array(); |
Andrey Andreev | ce747c8 | 2012-04-27 11:54:40 +0300 | [diff] [blame^] | 45 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 46 | /** |
| 47 | * List of loaded language files |
| 48 | * |
| 49 | * @var array |
| 50 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 51 | public $is_loaded = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 53 | /** |
| 54 | * Initialize language class |
Andrey Andreev | ce747c8 | 2012-04-27 11:54:40 +0300 | [diff] [blame^] | 55 | * |
| 56 | * @return void |
Timothy Warren | ad47505 | 2012-04-19 13:21:06 -0400 | [diff] [blame] | 57 | */ |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 58 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 59 | { |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 60 | log_message('debug', 'Language Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | // -------------------------------------------------------------------- |
| 64 | |
| 65 | /** |
| 66 | * Load a language file |
| 67 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | * @param mixed the name of the language file to be loaded. Can be an array |
| 69 | * @param string the language (english, etc.) |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 70 | * @param bool return loaded array of translations |
| 71 | * @param bool add suffix to $langfile |
| 72 | * @param string alternative path to look for language file |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | * @return mixed |
| 74 | */ |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 75 | public function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 76 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 77 | $langfile = str_replace('.php', '', $langfile); |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 78 | |
| 79 | if ($add_suffix == TRUE) |
| 80 | { |
Andrey Andreev | 8d5b24a | 2012-01-27 14:37:38 +0200 | [diff] [blame] | 81 | $langfile = str_replace('_lang', '', $langfile).'_lang'; |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 82 | } |
| 83 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 84 | $langfile .= '.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | if ($idiom == '') |
| 87 | { |
Andrey Andreev | 8d5b24a | 2012-01-27 14:37:38 +0200 | [diff] [blame] | 88 | $config =& get_config(); |
| 89 | $idiom = ( ! empty($config['language'])) ? $config['language'] : 'english'; |
| 90 | } |
| 91 | |
| 92 | if ($return == FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom) |
| 93 | { |
| 94 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | // Determine where the language file is and load it |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 98 | if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) |
| 99 | { |
| 100 | include($alt_path.'language/'.$idiom.'/'.$langfile); |
| 101 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | else |
| 103 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 104 | $found = FALSE; |
| 105 | |
| 106 | foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 108 | if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) |
| 109 | { |
| 110 | include($package_path.'language/'.$idiom.'/'.$langfile); |
| 111 | $found = TRUE; |
| 112 | break; |
| 113 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 115 | |
| 116 | if ($found !== TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 117 | { |
Derek Allard | ea9e4e0 | 2009-08-17 17:40:48 +0000 | [diff] [blame] | 118 | show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 122 | |
Frank Michel | cb272b6 | 2011-08-25 10:59:55 -0400 | [diff] [blame] | 123 | if ( ! isset($lang) OR ! is_array($lang)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | { |
| 125 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
Andrey Andreev | 8d5b24a | 2012-01-27 14:37:38 +0200 | [diff] [blame] | 126 | |
| 127 | if ($return == TRUE) |
| 128 | { |
| 129 | return array(); |
| 130 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | |
| 134 | if ($return == TRUE) |
| 135 | { |
| 136 | return $lang; |
| 137 | } |
| 138 | |
Andrey Andreev | 8d5b24a | 2012-01-27 14:37:38 +0200 | [diff] [blame] | 139 | $this->is_loaded[$langfile] = $idiom; |
Andrey Andreev | 4b13061 | 2012-01-10 16:09:55 +0200 | [diff] [blame] | 140 | $this->language = array_merge($this->language, $lang); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 141 | |
| 142 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile); |
| 143 | return TRUE; |
| 144 | } |
| 145 | |
| 146 | // -------------------------------------------------------------------- |
| 147 | |
| 148 | /** |
| 149 | * Fetch a single line of text from the language array |
| 150 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 151 | * @param string $line the language line |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | * @return string |
| 153 | */ |
Andrey Andreev | f9938a2 | 2012-01-07 22:10:47 +0200 | [diff] [blame] | 154 | public function line($line = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 155 | { |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 156 | $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 157 | |
| 158 | // Because killer robots like unicorns! |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 159 | if ($value === FALSE) |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 160 | { |
| 161 | log_message('error', 'Could not find the language line "'.$line.'"'); |
| 162 | } |
| 163 | |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 164 | return $value; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 169 | /* End of file Lang.php */ |
Andrey Andreev | 870ad19 | 2012-03-20 15:43:15 +0200 | [diff] [blame] | 170 | /* Location: ./system/core/Lang.php */ |