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