Merge pull request #993 from narfbg/develop-issue-128

Fix issue #128
diff --git a/system/core/Lang.php b/system/core/Lang.php
index 2963012..5cb0cad 100755
--- a/system/core/Lang.php
+++ b/system/core/Lang.php
@@ -42,7 +42,7 @@
 	 * @var array
 	 */
 	public $language =	array();
-	
+
 	/**
 	 * List of loaded language files
 	 *
@@ -52,6 +52,8 @@
 
 	/**
 	 * Initialize language class
+	 *
+	 * @return	void
 	 */
 	public function __construct()
 	{
@@ -76,22 +78,20 @@
 
 		if ($add_suffix == TRUE)
 		{
-			$langfile = str_replace('_lang.', '', $langfile).'_lang';
+			$langfile = str_replace('_lang', '', $langfile).'_lang';
 		}
 
 		$langfile .= '.php';
 
-		if (in_array($langfile, $this->is_loaded, TRUE))
-		{
-			return;
-		}
-
-		$config =& get_config();
-
 		if ($idiom == '')
 		{
-			$deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language'];
-			$idiom = ($deft_lang == '') ? 'english' : $deft_lang;
+			$config =& get_config();
+			$idiom = ( ! empty($config['language'])) ? $config['language'] : 'english';
+		}
+
+		if ($return == FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
+		{
+			return;
 		}
 
 		// Determine where the language file is and load it
@@ -123,6 +123,11 @@
 		if ( ! isset($lang) OR ! is_array($lang))
 		{
 			log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
+
+			if ($return == TRUE)
+			{
+				return array();
+			}
 			return;
 		}
 
@@ -131,9 +136,8 @@
 			return $lang;
 		}
 
-		$this->is_loaded[] = $langfile;
+		$this->is_loaded[$langfile] = $idiom;
 		$this->language = array_merge($this->language, $lang);
-		unset($lang);
 
 		log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
 		return TRUE;
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 03a020a..bdb418f 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -213,6 +213,7 @@
 -  Fixed a bug in Oracle's and MSSQL's delete() methods where an erroneous SQL statement was generated when used with limit().
 -  Fixed a bug in SQLSRV's delete() method where like() and limit() conditions were ignored.
 -  Fixed a bug (#1265) - Database connections were always closed, regardless of the 'pconnect' option value.
+-  Fixed a bug (#128) - :doc:`Language Library <libraries/language>` did not correctly keep track of loaded language files.
 
 Version 2.1.1
 =============