2
votes

I have a internalization problem with my Symfony 2 app. In the legacy site URL structure the default culture is "en" and there are a number of translated versions of the sites but for the english version the culture parameter is dropped from the URL like so:

/search - the culture "/en" is dropped
/fr/search - "/fr" is available
/es/search - likewise

I am trying to create routes in the app but I do not seem to find a solution to make the "/en" part of the URL optional.

I checked the documentation but it doesn't seem to have an option for that. Is it possible via the standard Symfony configuration or I should do a custom router for that?

1

1 Answers

2
votes

I would recommend looking at https://github.com/schmittjoh/JMSI18nRoutingBundle.

Basically this will allow you to internationalize your routes based on the country selected.

You can do this with traditional symfony routing such as

 /**
 * @Route("/{country}")
 */
 Class Something {

     /**
     *@Route("/search"), name="search"
     */
     public function searchAction(){

     }

 }

Where the {country} param will become part of the dynamic routing path.

But I would recommend jms solution as this will hook into translating your pages with eases, if you should wish to take this approach.