Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend translated routes

I have multiple routes for different locales:

Example:

Route for /de

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

Route for /en

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

Its possible somehow to have just one route instead of 2 on this case?

Note is not just the route which changes, also the type on the reqs and the default type.

like image 606
costa Avatar asked Nov 11 '16 18:11

costa


2 Answers

I see two different routes there Usually the internationalisation is on the page but not on the url

Let me be clear, you keep your url and with a parameter in the url you know the language of the page so

$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)'
    )
);

and depending of the parameter lang you display the correct message on your twig or phtml or html

Another way to do this changing the url is:

$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)'
    )
);
like image 136
Emiliano Avatar answered Nov 06 '22 14:11

Emiliano


I found the solution for the translations here:

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

like image 32
costa Avatar answered Nov 06 '22 15:11

costa