Damn, I thought I could get away with being lazy 😛.
Fictional Situation:
Language definitions for shared data is stored in APPPATH/language/current_lang/current_lang.php
Language definitions for my frontend are stored in APPPATH/language/current_lang/frontend.php
Language definitions for my backend are stored in APPPATH/language/current_lang/backend.php
They’re separated like that for clarity.
I this situation I would probably autoload the language library, so the first language file is loaded in your constructor.
In my frontend controller I would normally do:
$this->lang->load('frontend', current_lang);
But the constructor already grabbed the language so why should I do it again.
There are two solutions that I can think of. The first is an accessor method that returns the current language, so my call becomes:
$this->lang->load('frontend' $this->lang->get_lang() );
Or the other solution is overriding the load function to allow for this:
$this->lang->load('frontend');
The second solution makes more sense to me. Something like this should do it:
class MY_Language extends CI_Language
{
// ADDED THIS
var $lang;
function MY_Language()
{
parent::CI_Language();
global $RTR;
//get the language from uri segment
$lang_abbr = $RTR->uri->segment(1);
$lang_uri_abbr = $RTR->config->item('lang_uri_abbr');
//or from the config language
if(!isset($lang_uri_abbr[$lang_abbr]))
{
$user_lang = $RTR->config->item('language');
$lang_abbr = $RTR->config->item('language_abbr');
}
else
$user_lang = $lang_uri_abbr[$lang_abbr];
// AND THIS
$this->lang = $user_lang;
//....
}
function load($langfile)
{
parent::load($langfile, $this->lang);
}
}