I'm having trouble with locale routes in symfony 2.5. Let's say my default language ist english. My example route is /user/register/. If I request it without any locale it should appear the english translation. If I request it with a locale (e.g. /fr/user/register/) it should appear with it. This can be done with the following:
/**
* @Route("/{_locale}/user/register/")
* @Route("/user/register/")
* @Template()
*/
public function registerAction(Request $request)
{
$locale = $request->getLocale();
$translated = $this->get('translator')->trans('test.output');
echo $locale."<br>".$translated;
exit();
}
Now I have to questions to this:
- How can I simply avoid that a user can call the route with the default language as a locale? In my example english is the default language, so /en/user/register/ would have the same output as /user/register/. I don't want to make a 301-redirect in each controller-action!
- Is there no simple way to annotate a route with and without locale with one route-annotation?