0
votes

I am porting a PHP application from a 'own' 'framework' to Zend Framework (1.11.11) together with Doctrine2. This all wents well except that the application is available in two languages, Dutch and German. I am looking for a way to make two URL's accesable:

I tried this with the Regex route but it isn't nice since now the 'page' parameter must always being given when assembling:

resources.router.routes.viewreviews.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.viewreviews.route = "(klantbeoordelingen|kundenbewertung)[/]?([0-9]*)"
resources.router.routes.viewreviews.reverse = "%s/%d"
resources.router.routes.viewreviews.defaults.module = "default"
resources.router.routes.viewreviews.defaults.controller = "review"
resources.router.routes.viewreviews.defaults.action = "index"
resources.router.routes.viewreviews.map.name = 1
resources.router.routes.viewreviews.map.page = 2

The point is that it needs to be possible I should onmit the page param which now is impossible. I could make two regex routes though but that wouldn't be a nice approach. Cause I would get A LOT of routes which all of them almost look the same.

I think I am not looking for chained routes since the language is not included in the URL. The language is defined by the domainname you are accesing (.nl or .de).

Are there any ideas? Tips?

1

1 Answers

1
votes

After some research there is a solution. What I did is the following:

  • I rewrote my routes in a routes.xml file. Example:

    <viewreviews>
        <type>BestBuy_Router_Route</type>
        <route>@klantbeoordelingen/:page</route>
        <translate>klantbeoordelingen</translate>
        <defaults>
            <module>default</module>
            <controller>review</controller>
            <action>index</action>
            <page>0</page>
        </defaults>
    </viewreviews>
    

Note the @ in the route configuration. This will cause it to be translated. Then I add a meangless (for ZF) tag 'translate' so it will be picked up by Poedit.

  • The I edit my .po file and do the following in poedit: poedit and xml files

  • Then I crawl my XML file with poedit and It will find the tags and will question you to translate them.

  • After you translated these you make sure the correct translator is set in your router. I do this in my routeStartup cycle in a own written frontcontroller plugin:

        Zend_Controller_Router_Route::setDefaultLocale($translate->getLocale());
        Zend_Controller_Router_Route::setDefaultTranslator($translate);
    

$translate is a Zend_Translate object.

This should work for you. Translated routes only works with Zend_Controller_Router_Route. I extended this class and improved (BestBuy_Router_Route) cause I wanted all routes to be assembled lower cased etc.

Cheers!