我想嘗試Zend Framework中的路由轉換,但是我使用的是gettext適配器,大多數教程都帶有PHP轉換適配器,所以我遇到了難題使它工作。使用ZF的gettext適配器翻譯路由段
在主要的bootstrap.php我有我設置的路由方法:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$translator = Zend_Registry::get('Zend_Translate');
Zend_Controller_Router_Route::setDefaultTranslator($translator);
$routerRoute = new Zend_Controller_Router_Route('@about',
array(
'module' => 'default',
'controller' => 'index',
'action' => 'about'
)
);
$router->addRoute('about', $routerRoute);
這適用於路徑。 我會粘貼,我設置了Zend_Framework的代碼,但它基本上加載*.mo
文件取決於當前會話語言:
$langParam = $this->getSessionLang();
$localeString = $languages[$langParam];
$locale = new Zend_Locale($localeString);
$moFilePath = $langFolder . $langParam . '.mo';
if (!file_exists($moFilePath)) {
throw new Zend_Exception('File does not exist: ' . $moFilePath);
}
$translate = new Zend_Translate(
array(
'adapter' => 'gettext',
'content' => $moFilePath,
'locale' => $locale,
'ignore' => array('.'), // ignore SVN folders
'disableNotices' => ('production' === APPLICATION_ENV) // disable notices in Production
)
);
Zend_Registry::set('Zend_Translate', $translate);
Zend_Registry::set('Zend_Locale' , $locale);
這OFC,這就是所謂的prior
到路由。
我的問題:可以將gettext用作路由的轉換適配器,因爲我無法弄清楚如何捕獲@about
字符串,比如說poEdit?它可以?萬歲!怎麼樣?