blob: cbd4e38b85f04095b208e962f0fe2f9b1d4f4d76 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @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 Jones692c5482010-03-02 13:39:48 -060027class CI_Lang {
Derek Allard2067d1a2008-11-13 22:59:24 +000028
29 var $language = array();
30 var $is_loaded = array();
31
32 /**
33 * Constructor
34 *
35 * @access public
36 */
Derek Jones692c5482010-03-02 13:39:48 -060037 function CI_Lang()
Derek Allard2067d1a2008-11-13 22:59:24 +000038 {
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 mixed
51 */
Derek Jones692c5482010-03-02 13:39:48 -060052 function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
Derek Allard2067d1a2008-11-13 22:59:24 +000053 {
Derek Jones692c5482010-03-02 13:39:48 -060054 $langfile = str_replace(EXT, '', $langfile);
55
56 if ($add_suffix == TRUE)
57 {
58 $langfile = str_replace('_lang.', '', $langfile).'_lang';
59 }
60
61 $langfile .= EXT;
Derek Allard2067d1a2008-11-13 22:59:24 +000062
63 if (in_array($langfile, $this->is_loaded, TRUE))
64 {
65 return;
66 }
67
Derek Jones692c5482010-03-02 13:39:48 -060068 $config =& get_config();
69
Derek Allard2067d1a2008-11-13 22:59:24 +000070 if ($idiom == '')
71 {
Derek Jones692c5482010-03-02 13:39:48 -060072 $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language'];
Derek Allard2067d1a2008-11-13 22:59:24 +000073 $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
74 }
75
76 // Determine where the language file is and load it
Derek Jones692c5482010-03-02 13:39:48 -060077 if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile))
78 {
79 include($alt_path.'language/'.$idiom.'/'.$langfile);
80 }
81 elseif (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile))
Derek Allard2067d1a2008-11-13 22:59:24 +000082 {
83 include(APPPATH.'language/'.$idiom.'/'.$langfile);
84 }
85 else
86 {
87 if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile))
88 {
89 include(BASEPATH.'language/'.$idiom.'/'.$langfile);
90 }
91 else
92 {
Derek Allardea9e4e02009-08-17 17:40:48 +000093 show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
Derek Allard2067d1a2008-11-13 22:59:24 +000094 }
95 }
96
Derek Jones692c5482010-03-02 13:39:48 -060097
Derek Allard2067d1a2008-11-13 22:59:24 +000098 if ( ! isset($lang))
99 {
100 log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
101 return;
102 }
103
104 if ($return == TRUE)
105 {
106 return $lang;
107 }
108
109 $this->is_loaded[] = $langfile;
110 $this->language = array_merge($this->language, $lang);
111 unset($lang);
112
113 log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
114 return TRUE;
115 }
116
117 // --------------------------------------------------------------------
118
119 /**
120 * Fetch a single line of text from the language array
121 *
122 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200123 * @param string $line the language line
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 * @return string
125 */
126 function line($line = '')
127 {
128 $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
129 return $line;
130 }
131
132}
133// END Language Class
134
Derek Jones692c5482010-03-02 13:39:48 -0600135/* End of file Lang.php */
136/* Location: ./system/core/Lang.php */