0

I'm trying to set the local automatically if none is specified in the url.

What I want to to realize is:

if the user enters the site www.example.com is automatically set to the English language.

I tried this:

# homepage not localized: load the homepage with default language
index_not_localized:
   path:   /
   defaults:  { _controller: "AcmeSiteBundle:Default:index", _locale: en }


acme_site:
   resource: "@AcmeSiteBundle/Controller/"
   type:     annotation
   prefix:   /{_locale}
   defaults:  { _locale: en }
   requirements:
       _locale:  en|it

but if I do not put the language in the URL gives me this error:

Unable to generate a URL for the named route "_demo" as such route does not exist.

What am I doing wrong?

  • Not a direkt answer to your question, but take a look into the [JMSI18nRoutingBundle](http://jmsyst.com/bundles/JMSI18nRoutingBundle). It's awesome and resolves a lot of i18n for routes automagically. :) – althaus Jul 15 '13 at 08:27
  • Thanks, but you can not use the bundles for everything, this should be a feature of Symfony2 and it should work without external bundle! –  Jul 15 '13 at 12:23

1 Answers1

0
Unable to generate a URL for the named route "_demo" as such route does not exist.

This exception means the following:

When you don't put the language in the URL, it goes to a controller action (through a route) and somewhere in the action (possibly the template) it tries to create a URL with the method path or url of router service and it breaks because your Symfony application doesn't have a route called _demo.

Thomas Potaire
  • 6,166
  • 36
  • 39