Bonjour à tous j'essaie de faire un site en multilangue histoire d'apprendre la traduction avec symfony.
Tous se passe bien tous marche si je tapre index/en le site est en anglais et si je tapre index/fr le site est en français.
cependant si je dump $request->getLocale() cela me retourne toujours fr même si je suis sur le lien index/en.
Pourquoi la variable locale ne change pas en en ?
Merci
Service.yml:
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'fr'
app_locales: en|fr
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
bind:
$locales: '%app_locales%'
$defaultLocale: '%locale%'
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
app.mailer_helper:
class: App\Service\EmailHelper
public: true
arguments:
- '%env(MAILER_FROM)%'
App\Service\EmailHelper: '@app.mailer_helper'
app.exception.listener:
class: App\Listener\ExceptiontListener
arguments:
- '@session.flash_bag'
- '@router'
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
app.kernel.listener:
class: App\Listener\KernelRequestListener
arguments:
- '@security.helper'
- '@router'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
Route de mon controller
@Route("/{_locale}", name="index", defaults={"_locale":"%locale%"}, methods={"GET","POST"})
Bon j'ai pu résoudre mon problème en regardant la doc de symfony.
Merci à tous
voici le lien, faut crée un eventsubscriber
https://symfony.com/doc/current/session/locale_sticky_session.html