1
votes

I tried to separate my some of my components (e.g. nav bar) based on this cookbook article. However, I'm having difficulty setting the locale. In the example, the controller has no route. I think this is how it should be, because the nav bar alone should not have a route. However, the locale of the subrequest is then set to the default value, "en" in my case. The funny thing is that the translator component still works, i.e. gets the correct strings. However, my custom services, which use setter injection to get the current locale from the current request, now always use the default locale while a subrequest is in progress.

What is the correct way to get this working? How does Symfony's translator component get the current locale?

EDIT

Apparently the translator component only sets the locale for the outermost request. Once its set, its set. I should probably to it the same way.

1

1 Answers

0
votes

you just passes the current request so that it passes the parameters like the _local,...

Exemple:

{% render "MyBundle:Controller:someAction" with { 'originalRequest' : app.request } %}


public function someAction(Request $originalRequest)
{
    // do something
}