如何使用zend..i中的cookie使网站多语言现在已经使用route方法创建了

时间:2015-08-07 07:10:06

标签: zend-framework cookies multilingual

你好我在zend中使用我的自定义创建的zend插件进行了多语言设置,但现在要求是更改,我想使网站没有像lang/**这样的参数

这是插件。

public function routeShutdown(Zend_Controller_Request_Abstract $request)
{

    $lang = $request->getParam('lang', null);

    $translate = Zend_Registry::get('Zend_Translate');

    if ($translate->isAvailable($lang)) {
        $translate->setLocale($lang);
    } else {
        $translate->setLocale('en');
    }

    // Set language to global param so that our language route can
    // fetch it nicely.
    $front = Zend_Controller_Front::getInstance();
    $router = $front->getRouter();
    $router->setGlobalParam('lang', $lang);
}

在我的引导程序中我做了这个......

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initTranslate() {
    $translate = new Zend_Translate('gettext', APPLICATION_PATH .                 "/langs/", null, array('scan' => Zend_Translate::LOCALE_DIRECTORY,   'disableNotices' => true));
    $registry = Zend_Registry::getInstance();
    $registry->set('Zend_Translate', $translate);

}

public function _initRoutes() {
    $this->bootstrap('FrontController');
    $this->_frontController = $this->getResource('FrontController');
    $router = $this->_frontController->getRouter();

    $langRoute = new Zend_Controller_Router_Route(
            ':lang/', array(
        'lang' => 'en',
            )
    );

    $defaultRoute = new Zend_Controller_Router_Route(
            ':controller/:action', array(
        'module' => ':module',
        'controller' => 'index',
        'action' => 'index'
            )
    );

    $defaultRoute = $langRoute->chain($defaultRoute);

    $router->addRoute('langRoute', $langRoute);
    $router->addRoute('defaultRoute', $defaultRoute);
}

protected function _initLanguage() {
    $front = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new Application_Plugin_Language());
}

}

不知道如何删除lang/frlang/en并使用COOKIE执行此操作可以提供帮助吗?

PS:Zend版本为1.12

0 个答案:

没有答案