/halogy/libraries/Language.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 123 lines · 57 code · 17 blank · 49 comment · 11 complexity · 51dfc807465790b227536c8ea5e78c58 MD5 · raw file

  1. <?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
  9. * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * Language Class
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Libraries
  21. * @category Language
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/libraries/language.html
  24. */
  25. class CI_Language {
  26. var $language = array();
  27. var $is_loaded = array();
  28. /**
  29. * Constructor
  30. *
  31. * @access public
  32. */
  33. function CI_Language()
  34. {
  35. log_message('debug', "Language Class Initialized");
  36. }
  37. // --------------------------------------------------------------------
  38. /**
  39. * Load a language file
  40. *
  41. * @access public
  42. * @param mixed the name of the language file to be loaded. Can be an array
  43. * @param string the language (english, etc.)
  44. * @return mixed
  45. */
  46. function load($langfile = '', $idiom = '', $return = FALSE)
  47. {
  48. $langfile = str_replace(EXT, '', str_replace('_lang.', '', $langfile)).'_lang'.EXT;
  49. if (in_array($langfile, $this->is_loaded, TRUE))
  50. {
  51. return;
  52. }
  53. if ($idiom == '')
  54. {
  55. $CI =& get_instance();
  56. $deft_lang = $CI->config->item('language');
  57. $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
  58. }
  59. // Determine where the language file is and load it
  60. if (file_exists(APPPATH.'language/'.$idiom.'/'.$langfile))
  61. {
  62. include(APPPATH.'language/'.$idiom.'/'.$langfile);
  63. }
  64. else
  65. {
  66. if (file_exists(BASEPATH.'language/'.$idiom.'/'.$langfile))
  67. {
  68. include(BASEPATH.'language/'.$idiom.'/'.$langfile);
  69. }
  70. else
  71. {
  72. show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
  73. }
  74. }
  75. if ( ! isset($lang))
  76. {
  77. log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
  78. return;
  79. }
  80. if ($return == TRUE)
  81. {
  82. return $lang;
  83. }
  84. $this->is_loaded[] = $langfile;
  85. $this->language = array_merge($this->language, $lang);
  86. unset($lang);
  87. log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
  88. return TRUE;
  89. }
  90. // --------------------------------------------------------------------
  91. /**
  92. * Fetch a single line of text from the language array
  93. *
  94. * @access public
  95. * @param string $line the language line
  96. * @return string
  97. */
  98. function line($line = '')
  99. {
  100. $line = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
  101. return $line;
  102. }
  103. }
  104. // END Language Class
  105. /* End of file Language.php */
  106. /* Location: ./system/libraries/Language.php */