views:

18

answers:

1

Hi,
My localization files (.po) work if I change the default language, but I can't make the routes working, here's what I've got atm:

Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
Router::connect('/login/*', array('controller' => 'users', 'action' => 'login'));
Router::connect('/logout/*', array('controller' => 'users', 'action' => 'logout'));
Router::connect('/register/*', array('controller' => 'users', 'action' => 'register'));
Router::connect('/:lang/:controller/:action/*', array('lang' => 'en'), array('lang' => 'en|fr'));

But when I try : domain.com/fr/login, the cake is looking for the "fr" controller.

I am using this function in the AppController beforeFilter to switch between languages:

    function setLanguage() {
        if(!isset($this->params['lang']))
        {
            $this->params['lang'] = 'en';
        }
        $lang = $this->params['lang'];
        App::import('Core', 'i18n');
        $I18n =& I18n::getInstance();
        $I18n->l10n->get($lang);
        foreach (Configure::read('Config.languages') as $lang => $locale)
        {
            if($lang == $this->params['lang'])
            {
                $this->params['locale'] = $locale['locale'];
            }
        }
    }

Cheers,
Nicolas.

+1  A: 

You do not have a login controller. So your bottom route does not match and Cake then tries the default by looking for an fr controller.

Routes don't interact as you expect them to:

/login - would match your second route

/fr/users/login - would match your last route.

/fr/login - does NOT intelligently "merge" the two routes. You need to explicitly make such a route.

Martin Westin
Thanks for your explanations. Here's the working rule I added then: `Router::connect('/:lang/login/*', array(), array('lang' => 'en|fr', 'controller' => 'users', 'action' => 'login'));`
Nicolas