开发者

Multilanguage site in Codeigniter

I'm starting a new site project in Codeigniter. I need this site to be multilingual, where English will be the default language. I know how the language class in codeigniter works, and I am already using it.

My concern is that I need the URL to be shown in the selected language. I'll explain myself with an example:

When English language is selected, I have this URL: www.domain.com/cars/list_cars where cars is the controller and list_cars is the method in charge of calling the appropriate view.

When Spanish language language is selected, I would like the URL to show as www.domain.com/coches/mostr开发者_如何学Car_coches

Which is the best way to achieve this? The only way I can think of is by changing routes.php with something like:

$route['cars/list_cars'] = 'coches/mostrar_coches';

Is there any better/easier way of achieving this?

Thanks!


I built the concebe.com with CodeIgniter and Url translated. My solution was to redirect all requests to only one controller, which is responsible for calling other functions depending on the translation. see below:

function dinamic($js,$page,$item=NULL,$id=NULL)
{

    switch ($page)
    {
        case $this->lang->line('products'):
            $page='products';
        break;
        case $this->lang->line('about_us'):
            $page='about_us';
        break;
        ...
    }

    //switch page
    switch ($page)
    {
        case 'contact_us':
            $this->template->render($js,$this->_contact_us($js));
            return;
        break;
    }

This is not a clever solution and don't help you too, because is harder, but I have to differentiate the js call also, and this was the only way, I hope this help someone.

Constrains:when switch language, you lose the page were you where.


I did what you propose, using routes.php for your localised url segments. Works fine for me but for every page you do need a new entry in your routes file.


Translating your controller and method names is a headache waiting to happen. The benefits to your SEO are so minimal that it is really not worth doing, just make sure you have good content.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜