我正忙着用 ZF1 建立一个多语言网站。一切都很好,期待一件事,多语言部分与 zend 导航相结合。当我打开开发页面的 URL 时,标准语言是英语(http://website.nl/en)。导航栏(基于 zend 导航)显示如下网址:/en/blog、/en/events 等。但是当我将 de 语言从英语更改为荷兰语(http://website.nl/nl)时,导航栏仍然显示 /en/home、/en/blog 等。
有人知道问题是什么吗?
路由代码:
// Routing
$front = Zend_Controller_Front::getInstance();
// Remove default router
$router = $front->getRouter();
$router->removeDefaultRoutes();
// Add routers from config
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/routes.xml');
$router->addConfig($config, 'routes');
导航代码:
$this->bootstrap('layout');
$this->bootstrap('view');
$layout = $this->getResource('layout');
$view = $layout->getView();
// Set path to navigation.xmls
$config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml');
// ACL
$acl = new Application_Model_Acl();
// Get the identity of the user
$auth = Zend_Auth::getInstance()->getIdentity();
$navigation = new Zend_Navigation($config);
$view->navigation($navigation)
->setAcl($acl)
->setRole($auth->role);
部分路由xml
<cameloth type="Zend_Controller_Router_Route_Hostname">
<route>websiteurl</route>
<defaults _layout="sitecameloth/layout" module="siteCameloth" />
<chains>
<locale>
<route>:locale</route>
<defaults controller="index" locale="en" />
<reqs locale="[a-z]{2,3}" />
<chains>
<index>
<route></route>
<defaults _layout="sitecameloth/front" action="index" />
</index>
<news>
<route>blog</route>
<defaults controller="news" />
<chains>
<list>
<route>:page</route>
<defaults action="list" page="1" />
</list>
<read>
<route>:id/:title</route>
<defaults action="read" />
</read>
</chains>
</news>
语言环境插件
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$lang = $request->getParam('locale', '');
if ($lang !== 'en' && $lang !== 'nl')
$request->setParam('locale', 'en');
$lang = $request->getParam('locale');
if ($lang == 'en')
$locale = 'en_US';
else
$locale = 'nl_NL';
$zl = new Zend_Locale();
$zl->setLocale($locale);
Zend_Registry::set('Zend_Locale', $zl);
$translate = new Zend_Translate('gettext', APPLICATION_PATH . '/languages/' . $locale . '.mo');
Zend_Registry::set('Zend_Translate', $translate);
}