ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Change language in config.php dynamic [RESOLVED]

November 01, 2007 3:40pm

Subscribe [10]
  • #16 / Jan 16, 2008 6:34am

    xwero

    4145 posts

    @michaĆ«l : Sorry for the late answer, your post got lost during dinner 😉

    I just used it myself and it works great but i added an extra check

    class MY_Language extends CI_Language
    {
        
        
        function MY_Language()
        {
            parent::CI_Language();
        }
        
        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));    
                }
            }
        }
        
    }

    i use it as follows

    // controller
    class Admin extends Controller
    {
        
        function Admin()
        {
            parent::Controller();
            $this->lang->load('cms_form_msg');
            $this->lang->load('cms_form');
            $this->lang->switch_to($this->session->userdata('language'));
        }
    
            function langswitch()
        {
            $this->session->set_userdata('language',$this->uri->segment(3));
            redirect(str_replace('_','/',$this->uri->segment(4)));
        }
    }
    // view (the site_url function replaces the forward slashes with underscores)
    <a >uri->uri_string().'/'); ?>">English</a>

    I’m using a session variable but nothing stops you to use an url segment.

  • #17 / Dec 29, 2010 12:46pm

    Sixer

    15 posts

    Thanks for this. Works like a charm.

    Note: It doesn’t work as expected if $this->config->set_item(‘language’,’...’) is not done before the language switch is used. So set the language in the config using $this->config->set_item() before you attempt to use $this->lang->switch_to().

  • #18 / Jan 21, 2011 7:22am

    periback

    1 posts

    I had the same problem and it helped me a log! thanks

  • #19 / Nov 22, 2012 4:40pm

    franboud

    5 posts

    Thanks for all the tips! It helped me overcome a problem.
    Thanks again.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases