Welcome Guest, Not a member yet? Register   Sign In
Language Class Bug!
#2

[eluser]WanWizard[/eluser]
Not really a bug, but more a missing feature...

The language library assumes that you set the language before you start processing (and loading language files), so you will never have a mixed language situation.

Instead of modifying the core library (which is never a good idea), extend the Language library and add a switch_language method:
Code:
class MY_Language extends CI_Language
{
    /**
     * Constructor
     *
     * @return void
     * @access public
     */
    function MY_Language()
    {
        // call the parent constructor
        parent::CI_Language();

        // Logs initialization message for debugging
        log_message('debug', 'MY Language Class Extension Initialized');
    }
    /**
     * switch languages, reload all loaded language files if needed
     *
     * @access    public
     * @param    string    the language (english, etc.)
     * @param    boolean    ignore errors or not
     * @return    void
     */
    function switch_language($idiom = '', $silent = FALSE)
    {
        // get the CI superglobal object pointer
        $CI =& get_instance();

        // do we know to which idiom to switch?
        if ($idiom == '')
        {
            // no, nothing to do here
            return;
        }
        else
        {
            // is it a switch?
            if ( $CI->config->config['language'] == $idiom )
            {
                // no, nothing to do here
                return;
            }
            else
            {
                // reset the loaded language files array
                $this->is_loaded[] = array();

                // switch the default language
                $this->CI->config->set_item( 'language',$idiom );
            }
        }
    }
}

The version I use doesn't only switch languages, it also reloads all already loaded language files, so you don't have to do that manually. Because ExiteCMS uses an language file system different from standard CI, I left that code out.


Messages In This Thread
Language Class Bug! - by El Forum - 06-27-2010, 02:47 AM
Language Class Bug! - by El Forum - 06-27-2010, 04:42 AM
Language Class Bug! - by El Forum - 06-27-2010, 06:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB