Config for JMSI18nRoutingBundle
Closed this issue · 3 comments
Hi @lunetics,
have you ever used this bundle in combination with https://github.com/schmittjoh/JMSI18nRoutingBundle?
I was wondering which configuration is recommended. I currently have:
lunetics_locale:
allowed_locales: [de, en]
guessing_order:
- query
- router
- cookie
- session
- browser
session:
variable: _locale
It works ok but visiting http://test.com/en/?_locale=de
will set the cookie to de but translate fields in English.
So the wrong translation is related to #75. I just added an event listener for lunetics_locale.change
running $event->getRequest()->attributes->set('_locale', $event->getLocale());
and it works.
Which symfony version are you using?
I’ve got it running with the following configuration:
jms_i18n_routing:
...
cookie:
enabled: false
lunetics_locale
strict_mode: true
cookie:
name: locale
session:
variable: _locale
Can’t remember why (translations maybe?) but I had to add a listener for the onLocaleChange
$event->getRequest()->attributes->set('_locale', $event->getLocale());
to make it work correctly.
Routing:
home_redirect:
path: /
defaults:
_controller: lunetics_locale.switcher_controller:switchAction
route: home
statusCode: 301
useReferrer: false
_locale: ""
options: { i18n: false }
The _locale: ""
here is required so the router doesn’t return the default locale for the route (otherwise the routing guesser always takes that one).