Lang.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * Language Class
  19. *
  20. * @package CodeIgniter
  21. * @subpackage Libraries
  22. * @category Language
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/libraries/language.html
  25. */
  26. class CI_Lang {
  27. /**
  28. * List of translations
  29. *
  30. * @var array
  31. */
  32. var $language = array();
  33. /**
  34. * List of loaded language files
  35. *
  36. * @var array
  37. */
  38. var $is_loaded = array();
  39. /**
  40. * Constructor
  41. *
  42. * @access public
  43. */
  44. function __construct()
  45. {
  46. log_message('debug', "Language Class Initialized");
  47. }
  48. // --------------------------------------------------------------------
  49. /**
  50. * Load a language file
  51. *
  52. * @access public
  53. * @param mixed the name of the language file to be loaded. Can be an array
  54. * @param string the language (english, etc.)
  55. * @param bool return loaded array of translations
  56. * @param bool add suffix to $langfile
  57. * @param string alternative path to look for language file
  58. * @return mixed
  59. */
  60. function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
  61. {
  62. $langfile = str_replace('.php', '', $langfile);
  63. if ($add_suffix == TRUE)
  64. {
  65. $langfile = str_replace('_lang.', '', $langfile).'_lang';
  66. }
  67. $langfile .= '.php';
  68. if (in_array($langfile, $this->is_loaded, TRUE))
  69. {
  70. return;
  71. }
  72. $config =& get_config();
  73. if ($idiom == '')
  74. {
  75. $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language'];
  76. $idiom = ($deft_lang == '') ? 'english' : $deft_lang;
  77. }
  78. // Determine where the language file is and load it
  79. if ($alt_path != '' && file_exists($alt_path.'language/'.$idiom.'/'.$langfile))
  80. {
  81. include($alt_path.'language/'.$idiom.'/'.$langfile);
  82. }
  83. else
  84. {
  85. $found = FALSE;
  86. foreach (get_instance()->load->get_package_paths(TRUE) as $package_path)
  87. {
  88. if (file_exists($package_path.'language/'.$idiom.'/'.$langfile))
  89. {
  90. include($package_path.'language/'.$idiom.'/'.$langfile);
  91. $found = TRUE;
  92. break;
  93. }
  94. }
  95. if ($found !== TRUE)
  96. {
  97. show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
  98. }
  99. }
  100. if ( ! isset($lang))
  101. {
  102. log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
  103. return;
  104. }
  105. if ($return == TRUE)
  106. {
  107. return $lang;
  108. }
  109. $this->is_loaded[] = $langfile;
  110. $this->language = array_merge($this->language, $lang);
  111. unset($lang);
  112. log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
  113. return TRUE;
  114. }
  115. // --------------------------------------------------------------------
  116. /**
  117. * Fetch a single line of text from the language array
  118. *
  119. * @access public
  120. * @param string $line the language line
  121. * @return string
  122. */
  123. function line($line = '')
  124. {
  125. $value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
  126. // Because killer robots like unicorns!
  127. if ($value === FALSE)
  128. {
  129. log_message('error', 'Could not find the language line "'.$line.'"');
  130. }
  131. return $value;
  132. }
  133. }
  134. // END Language Class
  135. /* End of file Lang.php */
  136. /* Location: ./system/core/Lang.php */