Zend framework 使用ZF'转换管段;s gettext适配器

Zend framework 使用ZF'转换管段;s gettext适配器,zend-framework,gettext,zend-route,zend-translate,Zend Framework,Gettext,Zend Route,Zend Translate,我想在Zend框架中尝试路由转换,但我使用的是gettext适配器,而且大多数教程都有PHP转换适配器,所以我很难让它正常工作 在main Bootstrap.php中,我有一个设置路由的方法: $front = Zend_Controller_Front::getInstance(); $router = $front->getRouter(); $translator = Zend_Registry::get('Zend_Translate'); Zend_Controller_Ro

我想在Zend框架中尝试路由转换,但我使用的是gettext适配器,而且大多数教程都有PHP转换适配器,所以我很难让它正常工作

在main 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,它被称为路由之前的


我的问题是:gettext可以用作路由的翻译适配器吗,因为我不知道如何用poEdit捕捉
@about
字符串?可以吗?好极了怎么办?

嗯,我的mo都搞砸了。所以代码没有问题

以下是您如何编辑mo文件,以便路由可以对其进行翻译(我假设您的ZF i18n正在工作-翻译、区域设置等):

1。还记得吗?

$routerRoute = new Zend_Controller_Router_Route('@about',
     array(
      'module'     => 'default',
      'controller' => 'index',
      'action'     => 'about'
    )
);
2。看到“@about”字符串了吗?这是即将翻译的路径。那么,如何翻译一个字符串,以便poEdit捕获它呢?嗯,你没有;反正poEdit也不行。您可以手动编辑
.po文件

#ro.po
msgid  "about"
msgstr "despre"

#en.po
msgid  "about"
msgstr "about"
msgid应该与路径字符串匹配(减去“@”字符串,ofc)

3。现在用poEdit打开您的po文件。您将看到一个新字符串(惊讶吧?)。编译此
po
以获得ZF可以使用的新
mo
文件

4。现在我的
site.com/about
site.com/despre
路径可以工作了。