我想在 Zend Framework 中尝试路由翻译,但我使用的是 gettext 适配器,而且大多数教程都有 PHP 翻译适配器,所以我在让它工作时遇到了问题。
在主 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);
这适用于/about
路径。我将粘贴设置 Zend_Translate 的代码,但它基本上*.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 捕获字符串?它可以?万岁!如何?