Zend_Controller_Router_Route:找不到翻译器

发布于 2024-09-04 11:29:44 字数 1897 浏览 10 评论 0原文

我正在开发一个多语言应用程序。在引导程序中,有路由设置:

protected function _initRoutes() {

    $this->bootstrap('frontController');
    $router = $this->frontController->getRouter();

    // PAGES ROUTE
    $page = new Zend_Controller_Router_Route(
        ':language/:ident',
        array(
            'module'  => 'core',
      'controller' => 'pagine',
      'action'  => 'view'             
        ),
        array(
            'ident' => '[a-zA-Z-_0-9]{3,}',
         'language' => '[a-z]{2}'
        )
    );

    $registrazione = new Zend_Controller_Router_Route(
        ':language/@utenti/@registrati',
        array(
            'module'  => 'core',
'controller' => 'utenti',
'action'  => 'registrazione'
        ),
        array(
         'language' => '[a-z]{2}'
        )
    );

    $router->addRoute('page', $page);
    $router->addRoute('registrazione', $registrazione);

    .....

}

我无法将默认翻译器设置为 Zend_Controller_Router_Route (对于翻译的段),因为我不知道请求对象中的语言参数。 我在“routeShutdown”期间在多语言插件中获取语言参数:

class Activa_Controller_Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract {

public function routeShutdown(Zend_Controller_Request_Abstract $request) {
    $language = $request->getParam("language");
    $locale   = new Zend_Locale($language);

    $translate = new Zend_Translate('array', APPLICATION_PATH.'/config/lang/'.$language.'.php', $locale);

    Zend_Registry::set('Zend_Locale', $locale);
    Zend_Registry::set('Zend_Translate', $translate);

    Zend_Controller_Router_Route::setDefaultTranslator($translate);
    ////////////////////////
    // BUT NOW IS TOO LATE
    ////////////////////////
}

当我输入地址“http://servername/ it/utenti/registrati”我收到异常消息“找不到翻译”。

我该如何修复它? 安东尼奥(意大利)

I am developing a multilanguage application. In the bootstrap there is the routes setup:

protected function _initRoutes() {

    $this->bootstrap('frontController');
    $router = $this->frontController->getRouter();

    // PAGES ROUTE
    $page = new Zend_Controller_Router_Route(
        ':language/:ident',
        array(
            'module'  => 'core',
      'controller' => 'pagine',
      'action'  => 'view'             
        ),
        array(
            'ident' => '[a-zA-Z-_0-9]{3,}',
         'language' => '[a-z]{2}'
        )
    );

    $registrazione = new Zend_Controller_Router_Route(
        ':language/@utenti/@registrati',
        array(
            'module'  => 'core',
'controller' => 'utenti',
'action'  => 'registrazione'
        ),
        array(
         'language' => '[a-z]{2}'
        )
    );

    $router->addRoute('page', $page);
    $router->addRoute('registrazione', $registrazione);

    .....

}

I cannot set the default translator to Zend_Controller_Router_Route (for translated segments) because i don't know the language parameter in the request object.
I get the language parameter in Multilanguage Plugin during the "routeShutdown":

class Activa_Controller_Plugin_Multilanguage extends Zend_Controller_Plugin_Abstract {

public function routeShutdown(Zend_Controller_Request_Abstract $request) {
    $language = $request->getParam("language");
    $locale   = new Zend_Locale($language);

    $translate = new Zend_Translate('array', APPLICATION_PATH.'/config/lang/'.$language.'.php', $locale);

    Zend_Registry::set('Zend_Locale', $locale);
    Zend_Registry::set('Zend_Translate', $translate);

    Zend_Controller_Router_Route::setDefaultTranslator($translate);
    ////////////////////////
    // BUT NOW IS TOO LATE
    ////////////////////////
}

When i type the address "http://servername/it/utenti/registrati" i get the exception with the message "Could not find a translator".

How can i fix it?
Antonio (Italy)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

城歌 2024-09-11 11:29:44

创建一个 routeStartup() 插件,在其中扫描请求 URI 的区域设置/语言,例如使用简单的正则表达式。然后在路由器中创建并设置默认转换器。

Create a routeStartup() plugin, in which you scan the request URI for the locale/language, for example with a simple Regex. Then create and set the default translator in the Router.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文