New version submitted by TomB
[carbonphp.git] / Source / carbon / libraries / Language.php
blob1d487d116881b15aed019c785ff508f175732944
1 <?php
2 /*------------------------------------------------------------
3 * CarbonPHP framework (C) Tom Bell
4 * http://tombell.org.uk
5 *------------------------------------------------------------*/
7 if (!defined('CARBON_PATH'))
9 exit('Direct script access is not allowed.');
12 class Carbon_Language
14 protected $language = array();
15 protected $is_loaded = array();
17 public function __construct()
19 log_message('debug', 'Language.php - Carbon_Language class initialised');
22 public function load($langfile = '', $idiom = '', $return = false)
24 $langfile = str_replace(FILE_EXT, '', str_replace('_lang.', '', $langfile)) . '_lang' . FILE_EXT;
26 if (in_array($langfile, $this->is_loaded, true))
28 return true;
31 if ($idiom == '')
33 $carbon =& get_instance();
34 $def_lang = $carbon->config->get_config_item('language');
35 $idiom = ($def_lang == '') ? 'engliah' : $def_lang;
38 if (file_exists(APP_PATH . 'languages/' . $idiom . '/' . $langfile))
40 include(APP_PATH . 'languages/' . $idiom . '/' . $langfile);
42 else
44 if (file_exists(CARBON_PATH . 'languages/' . $idiom . '/' . $langfile))
46 include(CARBON_PATH . 'languages/' . $idiom . '/' . $langfile);
48 else
50 display_error('Unable to load the language file: languages/' . $langfile);
54 if (!isset($lang))
56 log_message('error', 'Language.php - Langauge file contains no data: languages/' . $idiom . '/' . $langfile);
57 return false;
60 if ($return == true)
62 return $lang;
65 $this->is_loaded[] = $langfile;
66 $this->language = array_merge($this->language, $lang);
67 unset($lang);
69 log_message('debug', 'Language.php - Language file loaded: languages/' . $idiom . '/' . $langfile);
70 return true;
73 public function line($line = '')
75 return ($line == '' || !isset($this->language[$line])) ? false : $this->language[$line];