Question

As the title suggests, I'm using Symfony in conjunction with the JMSTranslationBundle and JMSI18nBundle in order to serve translated routes.

Here's my currently configured route: /{location}/{profession}/{specialty}

So the route

/berlin/arzt/allgemein

is successfully pushed to the correct controller and action.

The JMSI18nBundle is automagically prefixing my English routes with /en/. This works for every other route with a non-dynamic component (such as /profile/{slug}/). This DOES NOT work, however, when using the English version of the above example. i.e.

/en/berlin/doctor/general

I'm guessing the router is not reading this properly as the English version of the normal route, and instead tries to assign location = en, profession = berlin, etc, which is obviously incorrect.

I've tried defining optional parameters, more complicated regexes, and trailing slashes for the translation (all with cache flushes in between). None of this works. What DOES work, is inserting a pointless non-dynamic component, i.e. /en/s/berlin/doctor/general etc

As a part of the business requirements, we don't want this additional pointless non-dynamic URL component.

So, my question is: how can I use (prefixed) translatable URLs in Symfony that contain nothing but dynamic fields?

Your help is greatly appreciated!

Was it helpful?

Solution

Solved:

As is the norm with Friday-afternoon problems, I found I had a $ inside my translated route rule, like so:

/{location}/{$profession}/{specialty}

Removing it and flushing the cache resulted in the route working.

tl;dr - PEBKAC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top