Reputation: 734
I am trying to load multiple language files in my CodeIgniter 3 project. Everything works fine as long as I load 1 language file at a time. When I try to load the language files using an array then it returns a NULL
value.
// This works fine:
$this->lang->load('homepage_lang', 'dutch');
$this->lang->load('login_lang', 'dutch');
// This does not work:
$this->lang->load(array('homepage_lang', 'login_lang'), 'dutch');
According to the CodeIgniter documentation this code should work:
http://www.codeigniter.com/user_guide/libraries/language.html#loading-a-language-file
In their example code they don't have any other parameters, but even when I leave mine out (the 'dutch' one) I am still unable to use an array. Any ideas on how to fix this?
Upvotes: 2
Views: 1332
Reputation: 1045
I think you will have to remove the trailing _lang
from the language file names. The rest of your code looks fine.
EDIT
While looking through the CodeIgniter 3 core source code I found the language load function:
public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
if (is_array($langfile))
{
foreach ($langfile as $value)
{
$this->load($value, $idiom, $return, $add_suffix, $alt_path);
}
return;
}
etc...
This means that when the first parameter is an array it will loop the array. After looping it will return nothing to stop further execution of the function. I think that's the reason why you get a NULL
value.
Even though the load function will return null, both language files will be loaded and available.
Upvotes: 1