I just started with Symphony, I'm trying to create a multinayet website, but I want to change the local level The problem is
I read some posts and I read the documentation about this but there is no change in locale, I try:
Public function indexation ( ) {$ This- & gt; Get ('session') - & gt; Set ('_ locale', 'fr'); $ Request = $ this- & gt; GetRequest (); $ Locale = $ request-> GetLocale (); $ $ --- ($ PhoneMainBundle: Default: index.html.twig ', Return Array (' Locale '=> $ Locale)); } but the values in the $ locale are always 'n' (my default location)
I also
public function index action ( ) {$ This- & gt; Receive ('session') - & gt; Set ('_ locale', 'fr'); $ Request = $ this- & gt; GetRequest (); $ Request & gt; SetLocale ('fr'); $ Locale = $ request-> GetLocale (); $ $ --- ($ PhoneMainBundle: Default: index.html.twig ', Return Array (' Locale '=> $ Locale)); } In this case $ locale is fr fraud but translations are always from messages.en.yml
I want to know the user locale for the first time $ Using an _SERVER ['HTTP_ACCEPT_LANGUAGE'], maybe using a listener on each page realization?
And after that I will make a way to change the locale
but I have to find out
based on and answer
Language Engineer. Php: & lt ;? Php namespace Acme \ UserBundle \ EventListener; Use Symfony \ Component \ HttpFoundation \ session \ session; Use Symfony \ Component \ Security \ Http \ Event \ InteractiveLoginEvent; Use Symfony \ Component \ HttpKernel \ Event \ GetResponseEvent; Use Symfony \ Component \ HttpKernel \ HttpKernelInterface; Class LanguageList {Private $ Session; Public function set session (session $ session) {$ this- & gt; Session = $ session; } Public Function (GetResponseEvent $ event) {If (HttpKernelInterface :: MASTER_REQUEST! == $ event-> getRequestType ()) {Return; } $ Request = $ event- & gt; GetRequest (); $ Request- & gt; Setlokel ($ request- & gt; Matching Language (Array ('N', 'D')); }} services.yml: acme.language.kernel_request_listener: Class: Acme \ UserBundle \ EventListener \ LanguageListener tag : - {name: kernel.event_listener, event: kernel.request, method: setLocale} Regarding finding the wrong location in a twig, there are several different reasons for the SO Search through, you will definitely find the answer. Make sure your '_local' var is defined correctly, make sure that you put your languages in the right place, etc. Undoubtedly, read the last version of the documents again:
No comments:
Post a Comment