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 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 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 |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 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 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 46 | var $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 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | var $is_loaded = array(); |
| 53 | |
| 54 | /** |
| 55 | * Constructor |
| 56 | * |
| 57 | * @access public |
| 58 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 59 | function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | { |
| 61 | log_message('debug', "Language Class Initialized"); |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------- |
| 65 | |
| 66 | /** |
| 67 | * Load a language file |
| 68 | * |
| 69 | * @access public |
| 70 | * @param mixed the name of the language file to be loaded. Can be an array |
| 71 | * @param string the language (english, etc.) |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 72 | * @param bool return loaded array of translations |
| 73 | * @param bool add suffix to $langfile |
| 74 | * @param string alternative path to look for language file |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | * @return mixed |
| 76 | */ |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 77 | function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 79 | $langfile = str_replace('.php', '', $langfile); |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 80 | |
| 81 | if ($add_suffix == TRUE) |
| 82 | { |
| 83 | $langfile = str_replace('_lang.', '', $langfile).'_lang'; |
| 84 | } |
| 85 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 86 | $langfile .= '.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | |
| 88 | if (in_array($langfile, $this->is_loaded, TRUE)) |
| 89 | { |
| 90 | return; |
| 91 | } |
| 92 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 93 | $config =& get_config(); |
| 94 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 95 | if ($idiom == '') |
| 96 | { |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 97 | $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang; |
| 99 | } |
| 100 | |
| 101 | // Determine where the language file is and load it |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 102 | if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile)) |
| 103 | { |
| 104 | include($alt_path.'language/'.$idiom.'/'.$langfile); |
| 105 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | else |
| 107 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 108 | $found = FALSE; |
| 109 | |
| 110 | foreach (get_instance()->load->get_package_paths(TRUE) as $package_path) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | { |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 112 | if (file_exists($package_path.'language/'.$idiom.'/'.$langfile)) |
| 113 | { |
| 114 | include($package_path.'language/'.$idiom.'/'.$langfile); |
| 115 | $found = TRUE; |
| 116 | break; |
| 117 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 119 | |
| 120 | if ($found !== TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 121 | { |
Derek Allard | ea9e4e0 | 2009-08-17 17:40:48 +0000 | [diff] [blame] | 122 | show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 126 | |
Frank Michel | cb272b6 | 2011-08-25 10:59:55 -0400 | [diff] [blame] | 127 | if ( ! isset($lang) OR ! is_array($lang)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | { |
| 129 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile); |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | if ($return == TRUE) |
| 134 | { |
| 135 | return $lang; |
| 136 | } |
| 137 | |
| 138 | $this->is_loaded[] = $langfile; |
Frank Michel | 373043f | 2011-08-25 00:11:00 -0400 | [diff] [blame] | 139 | $this->language = $this->language + $lang; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | unset($lang); |
| 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 | * |
| 151 | * @access public |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 152 | * @param string $line the language line |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 153 | * @return string |
| 154 | */ |
| 155 | function line($line = '') |
| 156 | { |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 157 | $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line]; |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 158 | |
| 159 | // Because killer robots like unicorns! |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 160 | if ($value === FALSE) |
Eric Barnes | e3c41cf | 2011-03-21 22:07:53 -0400 | [diff] [blame] | 161 | { |
| 162 | log_message('error', 'Could not find the language line "'.$line.'"'); |
| 163 | } |
| 164 | |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 165 | return $value; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | } |
| 169 | // END Language Class |
| 170 | |
Derek Jones | 692c548 | 2010-03-02 13:39:48 -0600 | [diff] [blame] | 171 | /* End of file Lang.php */ |
patwork | 571023b | 2011-04-11 11:56:41 +0200 | [diff] [blame] | 172 | /* Location: ./system/core/Lang.php */ |