Welcome Guest, Not a member yet? Register   Sign In
i18n library in CI2
#1

[eluser]Razican[/eluser]
I have been using this library in CI2 until last update.

http://maestric.com/doc/php/codeigniter_i18n

The problem is that since that update, I have changed the code to look like this:

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* MP_Config Class
*
* @subpackage    Libraries
* @author        Jérôme Jaglale
* @category    Libraries
* @link        http://maestric.com/en/doc/php/codeigniter_i18n
*/

class MP_Lang extends CI_Lang {

/*
|--------------------------------------------------------------------------
| Configuration
|--------------------------------------------------------------------------
|
| $languages    -> array with all the languaes inplemented
| $special        -> Not localized URIs
|
*/

    var $languages = array(
        'es' => 'spanish'/*,
        'en' => 'english',
        'eu' => 'basque'*/
    );

    var $special = array ('admin');

    function __construct()
    {

        parent::__construct();

        global $CFG;
        global $URI;
        global $RTR;

        $segment = $URI->segment(1);

        if (isset($this->languages[$segment]))
        {
            $language = $this->languages[$segment];
            $CFG->set_item('language', $language);
        }
        else if($this->is_special($segment))
        {
            return;
        }
        else
        {
            $CFG->set_item('language', $this->languages[$this->default_lang()]);

            header("Location: " . $CFG->site_url($this->lang($CFG->item('language')).$URI->uri_string()), TRUE, 302);
            exit;
        }
    }
    
    function lang()
    {
        global $CFG;        
        $language = $CFG->item('language');
        
        $lang = array_search($language, $this->languages);
        if ($lang)
        {
            return $lang;
        }
        
        return NULL;
    }

    function is_special($uri)
    {
        $exploded = explode('/', $uri);
        if (in_array($exploded[0], $this->special))
        {
            return TRUE;
        }
        if(isset($this->languages[$uri]))
        {
            return TRUE;
        }
        return FALSE;
    }

    function switch_uri($lang)
    {
        $CI =& get_instance();

        $uri = $CI->uri->uri_string();
        if ($uri != "")
        {
            $exploded = explode('/', $uri);
            if($exploded[1] == $this->lang())
            {
                $exploded[1] = $lang;
            }
            $uri = implode('/',$exploded);
        }
        return $uri;
    }

    function has_language($uri)
    {
        $first_segment = NULL;
        
        $exploded = explode('/', $uri);
        if(isset($exploded[0]))
        {
            if($exploded[0] != '')
            {
                $first_segment = $exploded[0];
            }
            else if(isset($exploded[1]) && $exploded[1] != '')
            {
                $first_segment = $exploded[1];
            }
        }
        
        if($first_segment != NULL)
        {
            return isset($this->languages[$first_segment]);
        }
        
        return FALSE;
    }

    function default_lang()
    {
        foreach ($this->languages as $lang => $language)
        {
            return $lang;
        }
    }

    function localized($uri)
    {
        if($this->has_language($uri)
        || $this->is_special($uri)
        || preg_match('/(.+)\.[a-zA-Z0-9]{2,4}$/', $uri))
        {}
        else
        {
            $uri = $this->lang() . '/' . $uri;
        }

        return $uri;
    }
}

/* End of file MP_Language.php */
/* Location: ./application/core/MP_Language.php */

I get this error:
Fatal error: Class 'CI_Controller' not found in /system/core/CodeIgniter.php on line 210

How can I solve it?


Messages In This Thread
i18n library in CI2 - by El Forum - 11-12-2010, 03:15 PM
i18n library in CI2 - by El Forum - 11-12-2010, 03:42 PM
i18n library in CI2 - by El Forum - 11-13-2010, 09:53 AM
i18n library in CI2 - by El Forum - 11-13-2010, 12:10 PM
i18n library in CI2 - by El Forum - 11-13-2010, 01:50 PM
i18n library in CI2 - by El Forum - 11-14-2010, 04:03 AM
i18n library in CI2 - by El Forum - 11-16-2010, 11:33 AM
i18n library in CI2 - by El Forum - 11-17-2010, 01:07 PM
i18n library in CI2 - by El Forum - 11-18-2010, 04:17 AM
i18n library in CI2 - by El Forum - 11-18-2010, 10:48 AM
i18n library in CI2 - by El Forum - 11-24-2010, 02:14 AM
i18n library in CI2 - by El Forum - 03-29-2011, 03:20 PM
i18n library in CI2 - by El Forum - 03-30-2011, 08:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB