Welcome Guest, Not a member yet? Register   Sign In
Multilingual website gestion
#1

[eluser]dorwin[/eluser]
Hi,

(For the record I'm french and beginner with CI so please excuse me and if you answer, could you please use easy words ?Wink )

So, I'm on a multilingual website. I found this post :
http://ellislab.com/forums/viewthread/101790/P0/ very helpfull so,

There im my route config :
Code:
$route['(en|fr)/(:any)'] = "$2/$1";

and there is a few code (wich is working (i think)) :

[algo]
if language is in URL (ex : site.com/en)
-> loading of the lang file (here "en")
else
-> check navigator lang
->if navigator lang = fr or en
-> redirect (rewrite the url) with $lang
else
->redirect with "en" as lang

Code :
Code:
//---CHECK LANG-----//
        if ($this->uri->segment(1) == "fr" OR $this->uri->segment(1) == "en") //si URL OK
        {
            //chargement du fichier de langue choisi
            $this->lang->load($this->uri->segment(2), $this->uri->segment(1));
        }
        else //sinon langue non précisé
        {
            //recherche de la langue du navigateur
            $lang = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
            $lang = strtolower(substr(chop($lang[0]),0,2));
            
            if ($lang == "fr" OR $lang == "en") //si le navigateur est en FR ou EN
            {
                //on réécrit l'url avec la langue du navigateur
                redirect(base_url().$lang.$this->uri->uri_string());
            }
            else    //par exemple RU, IT, etc..
            {
                //on redirige page EN (english)
                redirect(base_url().'en'.$this->uri->uri_string());
            }
                
        }

I just developped it and i know it's optimisable, but :
the question is, have I to put this code on every constructor of every controller ?
I know i can put this on a function but the problem is the same, I have to call it on every constuctor ?

First, is there a place I can put this code just one time and,
Is my code (optimized or not) the good solution for multilingue website ?

Thanks !


Messages In This Thread
Multilingual website gestion - by El Forum - 01-10-2010, 07:09 PM
Multilingual website gestion - by El Forum - 01-11-2010, 01:04 AM
Multilingual website gestion - by El Forum - 01-11-2010, 11:27 AM
Multilingual website gestion - by El Forum - 01-11-2010, 01:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB