Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Rick Ellis | e4a7db4 | 2008-09-12 23:35:09 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2008, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 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
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 24 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 25 | * @link http://codeigniter.com/user_guide/libraries/language.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 26 | */
|
| 27 | class CI_Language {
|
| 28 |
|
| 29 | var $language = array();
|
| 30 | var $is_loaded = array();
|
| 31 |
|
| 32 | /**
|
| 33 | * Constructor
|
| 34 | *
|
| 35 | * @access public
|
| 36 | */
|
| 37 | function CI_Language()
|
| 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 void
|
| 51 | */
|
Derek Allard | 79ecefd | 2007-07-15 22:49:07 +0000 | [diff] [blame] | 52 | function load($langfile = '', $idiom = '', $return = FALSE)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 53 | {
|
| 54 | $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;
|
| 55 |
|
| 56 | if (in_array($langfile, $this->is_loaded, TRUE))
|
| 57 | {
|
| 58 | return;
|
| 59 | }
|
| 60 |
|
| 61 | if ($idiom == '')
|
| 62 | {
|
| 63 | $CI =& get_instance();
|
| 64 | $deft_lang = $CI->config->item('language');
|
| 65 | $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
|
| 66 | }
|
| 67 |
|
| 68 | // Determine where the language file is and load it
|
| 69 | if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile))
|
| 70 | {
|
| 71 | include(APPPATH.'language/'.$idiom.'/'.$langfile);
|
| 72 | }
|
| 73 | else
|
| 74 | {
|
| 75 | if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile))
|
| 76 | {
|
| 77 | include(BASEPATH.'language/'.$idiom.'/'.$langfile);
|
| 78 | }
|
| 79 | else
|
| 80 | {
|
| 81 | show_error('Unable to load the requested language file: language/'.$langfile);
|
| 82 | }
|
| 83 | }
|
| 84 |
|
Derek Allard | 79ecefd | 2007-07-15 22:49:07 +0000 | [diff] [blame] | 85 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 86 | if ( ! isset($lang))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 87 | {
|
| 88 | log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
|
| 89 | return;
|
| 90 | }
|
| 91 |
|
Derek Allard | 79ecefd | 2007-07-15 22:49:07 +0000 | [diff] [blame] | 92 | if ($return == TRUE)
|
| 93 | {
|
| 94 | return $lang;
|
| 95 | }
|
| 96 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 97 | $this->is_loaded[] = $langfile;
|
| 98 | $this->language = array_merge($this->language, $lang);
|
| 99 | unset($lang);
|
| 100 |
|
| 101 | log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
|
| 102 | return TRUE;
|
| 103 | }
|
| 104 |
|
| 105 | // --------------------------------------------------------------------
|
| 106 |
|
| 107 | /**
|
| 108 | * Fetch a single line of text from the language array
|
| 109 | *
|
| 110 | * @access public
|
Derek Allard | db25721 | 2008-06-20 05:56:51 +0000 | [diff] [blame] | 111 | * @param string $line the language line
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 112 | * @return string
|
| 113 | */
|
Derek Jones | cc1be0f | 2008-06-27 17:14:46 +0000 | [diff] [blame] | 114 | function line($line = '')
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 115 | {
|
Derek Allard | db25721 | 2008-06-20 05:56:51 +0000 | [diff] [blame] | 116 | $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
|
Derek Allard | db25721 | 2008-06-20 05:56:51 +0000 | [diff] [blame] | 117 | return $line;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 118 | }
|
| 119 |
|
| 120 | }
|
| 121 | // END Language Class
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame] | 122 |
|
| 123 | /* End of file Language.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 124 | /* Location: ./system/libraries/Language.php */ |