Zend 翻译路线

Zend translated routes

我有针对不同语言环境的多条路线:

示例:

/de 的路线

$routes['industry'] = array(
    'route' => 'branche/:type',
    'defaults' => array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'branche',
        'type' => 'automobil'
    ),
    'reqs' => array(
        'type' => '(automobil|textil)'
    )
);

/en 的路由

$routes['industry'] = array(
    'route' => 'industry/:type',
    'defaults' => array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'branche',
        'type' => 'car'
    ),
    'reqs' => array(
        'type' => '(car|textile)'
    )
);

在这种情况下,有可能只有一条路线而不是两条路线吗?

注意不仅改变了路线,还改变了请求的类型和默认类型。

我看到那里有两条不同的路线 通常国际化在页面上而不是在 url

让我说清楚,你保留你的 url 并且在 url 中有一个参数你知道页面的语言所以

$routes['industry'] = array(
    'route' => 'industry/:lang/:type',
    'defaults' => array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'branche',
        'type' => 'car',
        'lang' => 'en'
    ),
    'reqs' => array(
        'lang' => '(en|de)',
        'type' => '(car|textile)'
    )
);

并且根据参数 lang,您在树枝或 phtml 或 html

上显示正确的消息

改变 url 的另一种方法是:

$routes['industry'] = array(
    'route' => ':industry/:type',
    'defaults' => array(
        'module' => 'default',
        'controller' => 'index',
        'action' => 'branche',
        'type' => 'car',
        'industry' => 'industry'
    ),
    'reqs' => array(
        'industry' => '(industry|branche)',
        'type' => '(car|textile)'
    )
);

我在这里找到了翻译的解决方案:

https://dasprids.de/blog/2009/04/01/translated-segments-for-standard-route/