0

I'm trying to implement the locale in the routes. I can get it to work like host/en/page & host/fr/page with this snippet:

#routing.yml

app:
    resource: "@AppBundle/Controller/"
    type:     annotation
    prefix:   /{_locale}
    requirements:
        _locale: nl|en

But my goal is to be able to use host/page where the locale would not be in the url, but is set as a default locale.

How do I do this? I can't find it anywhere in the documentation.

Edit, trying out the JMSI18nRoutingBundle

additions:

# config.yml

jms_i18n_routing:
    default_locale: nl
    locales: [nl, en]
    strategy: prefix_except_default

.

# security.yml > firewalls section

form_login:
        login_path: _login
        check_path: _login
        csrf_token_generator: security.csrf.token_manager
    logout:
        path:   _logout
        target: /

.

# routing.yml

_logout:
    path: /logout
    options: { i18n: false }
_login:
    path: /login
    options: { i18n: false }

Routes are prefixed as they should, but I'm unable to use my login and logout routes.

SnelleJelle
  • 933
  • 5
  • 18
  • 35

1 Answers1

0

Use https://github.com/schmittjoh/JMSI18nRoutingBundle bundle.

In app/config.yml setup the bundle for default locale.

jms_i18n_routing:
    default_locale: nl
    locales: [nl, en]
    strategy: prefix_except_default
malcolm
  • 5,486
  • 26
  • 45
  • You should also remove requirements and prefix added before to routes. It cannot broke routes if default language is set, the routes stay as is. – malcolm May 12 '16 at 12:59
  • I'm editing my post to better reflect what I've tried so far – SnelleJelle May 12 '16 at 13:37
  • And you removed all the stuff from routing that you added before? For me the bundle always working perfect, I do nothing with routing, if I not translate routes in `translations/routes.en.yml` or any other language, all routes stay at is before. – malcolm May 12 '16 at 16:43
  • nope, all my routes are basic routes, the others are shown above. – SnelleJelle May 12 '16 at 16:46