Welcome Guest, Not a member yet? Register   Sign In
i18n routing problem
#1

[eluser]Bartolo![/eluser]
Hi all,

for my website i'm using the i18n library for multi-language support.

i 'installed' everything according to the manual in:

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

but the first redirect from website/ to website/language doesn't work.

the links with site_url(); also don't work.

when i add /language by hand everything is working again and the links contains /en and /nl.

background information:

i use htacces mod_rewrite (so without the index.php)

my website uses a subfolder (http://intranet/websites/website/home/index)


i hope someone recognizes the problem...

if you need some more information, off course i will bring you that ;-)

Thanks in advance!!!
#2

[eluser]Bartolo![/eluser]
Hi, me again...

i found some strange behavior in the code, i was placing some errors to see where the code was stop working.

down here you find a piece of the 18n library:

(the show_error() tags shown are only for illustration, watch these...)

Code:
function MY_Language()
    {
        parent::CI_Language();        
        
        global $CFG;
        global $URI;
        global $RTR;
        
        show_error('this is an error'); // this error is showing correctly
        
        $segment = $URI->segment(1);
        
        
        if (isset($this->languages[$segment]))    // URI with language -> ok
        {

            show_error('this is an error'); // this error is not being shown, so $this->languages[$segment] is not set. lets go to the 'else'

            $language = $this->languages[$segment];
            $CFG->set_item('language', $language);

            if ($RTR->scaffolding_request === TRUE)
            {
                // hide language segment for scaffolding code
                $RTR->uri->segments = $RTR->uri->rsegments;
            }
        }
        else if($this->is_special($segment)) // special URI -> no redirect
        {
            return;
        }
        else    // URI without language -> redirect to default_uri
        {

            show_error('this is an error'); // this error is also not being shown. so thats why the first redirect (without language) is not working. but why does this not work?
            
                        // set default language
            $CFG->set_item('language', $this->languages[$this->default_lang()]);

            // redirect
            header("Location: " . $CFG->site_url($this->localized($this->default_uri)), TRUE, 302);
            //header("Location: " . $CFG->site_url($this->localized($URI->uri_string)), TRUE, 302);
            exit;
        }
    }

i really don't get it...

edit:

...i just found the problem: the error was shown in the else if($this->is_special($segment)) part. The configuration was like:
Code:
// languages
    var $languages = array(
        'en' => 'english',
        'nl' => 'dutch'
    );

    // special URIs (not localized)
    var $special = array (
        ""
    );
    
    // where to redirect if no language in URI
    var $default_uri = 'home';

because the $special var was empty, at opening the page you always have the special var in the URI because it's empty too...

To the creator of the code: please notice in the manual that you HAVE to fill in the special URI, even when you haven't got one.




Theme © iAndrew 2016 - Forum software by © MyBB