0
votes

I am currently trying to set up a translated routing in a ZF2 Project. I already followed the instructions in this post: Zend Framework 2 - translating routes and got it to work.

Now I have the following problem: My URLs will look something like this:

www.example.com/en/registration (english)

www.example.com/de/anmeldung (same page in german)

To translate the {registration} part the router needs the locale which has to be set beforehand. But I want to be able to choose the language with the URL parameter (de/en), so I would basically have to set the router translation locale while the routing is in progress (MvcEvent::EVENT_ROUTE). Is there a way to do this?

I was able to set the locale by manually parsing the request uri before the routing starts, but that is not the most elegant solution and may lead to errors later.

Many thanks in advance,

Hans

1

1 Answers

0
votes

Have a look at this pull request:

https://github.com/zendframework/zf2/pull/5885

The idea is to set the locale of the translator depending on a parameter, namely "locale", of the route. Use this route definition and you're ready to go:

/:locale/{REGISTRATION}