CodeIgniter Forums

Full Version: Change language globally
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Sander Versluys[/eluser]
How to change the language globally for your codeigniter application?

Setting it like following doesn't work:

Code:
$this->config->set_item('language', 'nl');

The language files are present, i've changed the the full names to shorter ones. When i set the config file manually, it works.

El Forum

[eluser]xwero[/eluser]
Code:
function MY_Language()
    {
        parent::CI_Language();
    }
    /**
    * Makes switching between languages easier
    *
    *  example : http://ellislab.com/forums/viewreply/339962/
    */
    function switch_to($idiom)
    {
        $CI =& get_instance();
        if(is_string($idiom) && $idiom != $CI->config->item('language'))
        {
            $CI->config->set_item('language',$idiom);
            $loaded = $this->is_loaded;
            $this->is_loaded = array();
                
            foreach($loaded as $file)
            {
                $this->load(str_replace('_lang.php','',$file));    
            }
        }
    }
Something i added to the wiki many moons ago, this gets you started i think Wink

El Forum

[eluser]Sander Versluys[/eluser]
Thanks... good stuff, exactly what i needed!