开发者

Cakephp localization routes

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' => '开发者_如何学Pythonusers', '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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜