我正在開發一個多語種的web應用程序。我有來自xml文件的菜單元素,但我不知道如何翻譯菜單。另一方面,我可以像這樣在視圖中翻譯網站的正常內容:Zend框架菜單翻譯
<?=$this->translate->_('Members Login')
我的引導文件:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
private $_acl = null;
private $_auth = null;
protected function _initAutoLoad()
{
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH
));
if (Zend_Auth::getInstance()->hasIdentity()) {
Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->role);
} else {
Zend_Registry::set('role', 'guest');
}
$this->_acl = new Model_LibraryAcl();
$this->_auth = Zend_Auth::getInstance();
$fc = Zend_Controller_Front::getInstance();
$fc->registerPlugin(new Plugin_AccessCheck($this->_acl, $this->_auth));
return $modelLoader;
}
function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->doctype('HTML4_STRICT');
$view->headMeta()->appendHttpEquiv('Content-type','text/html;charset=UTF-8')
->appendName('description','The Best Freelance Projects');
$view->headTitle('Freelance Duty');
$navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
$navContainer = new Zend_Navigation($navContainerConfig);
$view->navigation($navContainer)
->setAcl($this->_acl)
->setRole(($this->_auth->getStorage()->read())?$this->_auth->getStorage()->read()->role:'guest')
->findAllBy('class', 'nav_header');
}
function _initSetTranslations()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$translate = new Zend_Translate('gettext',APPLICATION_PATH.'/languages/tr.mo','tr');
$translate->setLocale('tr');
$view->translate = $translate;
Zend_Registry::set('TranslationObject', $translate);
}
}
和這樣寫鑑於菜單:
echo $this->navigation()->menu()->setUlClass('nav_header');
我不知道如何翻譯菜單 有何評論?
在此先感謝
正如我在我的引導文件中寫道,我有alrady使用zend_translate。問題是關於菜單翻譯。因爲菜單內容不是常量值,它動態來自xml – 2011-02-12 22:44:50
這不重要,該菜單項來自XML。您將PARSED文件傳遞給構造函數`Zend_Navigation`,所以它應該能夠獲取菜單標籤並將其轉換。 – singles 2011-02-12 22:50:33