Search code examples
zend-frameworkzend-routezend-translate

Zend_Controller_Router_Route_Regex reverse route not translated


This is how my route looks like:

acc_long.type = Zend_Controller_Router_Route_Regex
acc_long.route = "@accommodation/([A-Za-z-]+)/([0-9A-Za-z-]+)-([0-9]+)"
acc_long.map.1 = 'location'
acc_long.map.2 = 'name'
acc_long.map.3 = 'id'
acc_long.defaults.controller    = "accommodation"
acc_long.defaults.action        = "index"
acc_long.defaults.module        = "default"
acc_long.defaults.location      = 'FALSE'
acc_long.defaults.name          = 'FALSE'
acc_long.defaults.id            = 'FALSE'
acc_long.reverse = "@accommodation/%s/%s-%d/"

But zend router doesn't translate it into a specific language, to german for example. I have all the translations available, and translation of routes is working fine in all routes except for Regex route?

Is there any way to translate it also?

Thank you very much!


Solution

  • The solutiuon is to use chaining, so the "static" part of the route is a separate route.

    for example

    language.type = Zend_Controller_Router_Route
    language.route = ":lang/"
    language.reqs.lang = "(en|de)"
    language.defaults.lang = "de"
    language.defaults.controller = "index"
    language.defaults.module = "default"
    language.defaults.action = "index"
    
    acc_long.type = Zend_Controller_Router_Route_Regex
    acc_long.route = "([A-Za-z-]+)/([0-9A-Za-z-]+)-([0-9]+)"
    acc_long.map.1 = 'location'
    acc_long.map.2 = 'name'
    acc_long.map.3 = 'id'
    acc_long.defaults.action        = "index"
    acc_long.defaults.location      = 'FALSE'
    acc_long.defaults.name          = 'FALSE'
    acc_long.defaults.id            = 'FALSE'
    acc_long.reverse = "%s/%s-%d/"
    
    acc.type = Zend_Controller_Router_Route
    acc.route = "@accommodation"
    acc.defaults.controller    = "accommodation"
    acc.defaults.action        = "index"
    acc.defaults.module        = "default"
    
    acc_long_chain.type = Zend_Controller_Router_Route_Chain
    acc_long_chain.chain = "language, acc, acc_long"
    

    And it works like a charm!