From c9e2b10f08a3c718e52e287e2dd14b880e4e3057 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 12 Jul 2007 12:14:45 +0000 Subject: added language files to autoload --- system/application/config/autoload.php | 15 +++++++++++++++ system/libraries/Language.php | 5 ----- system/libraries/Loader.php | 25 ++++++++++++++++++------- user_guide/changelog.html | 15 ++++++++------- user_guide/general/autoloader.html | 1 + user_guide/libraries/language.html | 9 +++------ 6 files changed, 45 insertions(+), 25 deletions(-) diff --git a/system/application/config/autoload.php b/system/application/config/autoload.php index 26e71f74c..85b65aa7f 100644 --- a/system/application/config/autoload.php +++ b/system/application/config/autoload.php @@ -80,6 +80,21 @@ $autoload['plugin'] = array(); $autoload['config'] = array(); +/* +| ------------------------------------------------------------------- +| Auto-load Language files +| ------------------------------------------------------------------- +| Prototype: +| +| $autoload['language'] = array('lang1', 'lang2'); +| +| NOTE: Do not include the "_lang" part of your file. For example +| "codeigniter_lang.php" would be referenced as array('codeigniter'); +| +*/ + +$autoload['language'] = array(''); + /* | ------------------------------------------------------------------- | Auto-load Core Libraries diff --git a/system/libraries/Language.php b/system/libraries/Language.php index 26775ec7e..94923a3e7 100644 --- a/system/libraries/Language.php +++ b/system/libraries/Language.php @@ -89,11 +89,6 @@ class CI_Language { return; } - if ($return == TRUE) - { - return $lang; - } - $this->is_loaded[] = $langfile; $this->language = array_merge($this->language, $lang); unset($lang); diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index abe3a1c37..7fa46c3ad 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -481,13 +481,24 @@ class CI_Loader { * Loads a language file * * @access public + * @param array * @param string + * @param bool * @return void */ - function language($file = '', $lang = '', $return = FALSE) + function language($file = array(), $lang = '') { $CI =& get_instance(); - return $CI->lang->load($file, $lang, $return); + + if ( ! is_array($file)) + { + $file = array($file); + } + + foreach ($file as $langfile) + { + $CI->lang->load($langfile, $lang); + } } // -------------------------------------------------------------------- @@ -813,7 +824,7 @@ class CI_Loader { return FALSE; } - // Load any custome config file + // Load any custom config file if (count($autoload['config']) > 0) { $CI =& get_instance(); @@ -823,15 +834,15 @@ class CI_Loader { } } - // Load plugins, helpers, and scripts - foreach (array('helper', 'plugin', 'script') as $type) - { + // Autoload plugins, helpers, scripts and languages + foreach (array('helper', 'plugin', 'script', 'language') as $type) + { if (isset($autoload[$type]) AND count($autoload[$type]) > 0) { $this->$type($autoload[$type]); } } - + // A little tweak to remain backward compatible // The $autoload['core'] item was deprecated if ( ! isset($autoload['libraries'])) diff --git a/user_guide/changelog.html b/user_guide/changelog.html index d8ffd8b19..0456be34e 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -65,11 +65,12 @@ Change Log

Version 1.5.4

Release Date: -- Still under development

To autoload resources, open the application/config/autoload.php file and add the item you want diff --git a/user_guide/libraries/language.html b/user_guide/libraries/language.html index 6a74cc963..7cc74b61d 100644 --- a/user_guide/libraries/language.html +++ b/user_guide/libraries/language.html @@ -115,12 +115,9 @@ is the language set containing it (ie, english). If the second parameter is mis

Where language_key is the array key corresponding to the line you wish to show.

Note: This function simply returns the line. It does not echo it for you.

- - - - - - +

Auto-loading Languages

+

If you find that you need a particular language globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the language(s) to the autoload array.

+

 

-- cgit v1.2.3-24-g4f1b