CodeIgniter Forums
Change language globally - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Change language globally (/thread-13694.html)



Change language globally - El Forum - 12-02-2008

[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.


Change language globally - El Forum - 12-02-2008

[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


Change language globally - El Forum - 12-02-2008

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