views:

55

answers:

0

I' m using codeigniter with po/mo files (I don't like the built in functions) I have an already made function that uses get variables to set the cookie with the language.

Now, codeigniter don't have the get but uses uris. This is the function that I'm using (it fires in the constructor):

private function locale(){

    $cookie_name = $this->cookie_lang;
    $uri = $this->uri->uri_to_assoc(3);

    if ($this->tools->isArray($uri)){
        $locale = $uri['locale'];
    }

    if ($locale) {
        setcookie("$cookie_name", $locale, 0, "/");
    } else {
        if( !isset($_COOKIE[$cookie_name]) && empty($_COOKIE[$cookie_name]) ) {
            setcookie("$cookie_name", 'it', 0, "/");
            $locale = 'it';
        } else {
            $locale = $_COOKIE[$cookie_name];
        }
    }   
    putenv("LC_ALL=$locale");
    setlocale(LC_ALL, $locale);
    bindtextdomain("default", "./locale");
    textdomain("default");
    $this->locale = $locale;
    return true;
}

And it works perfectly, setting the language is just a matter of appending:

locale/x

to the url. The problem is that I use uris for other purposes (for example loading a page)

page/x

This result in very long urls like:

www.site.com/controller/method/page/x/locale/y

Just to be able to set the language.

Are there easier (or better) method to set a language?

Thanks