I am trying to add language switcher and Locale was only working after page refresh(Symfony Locale only working after page refresh).So I am planning to use Symfony Locale Swicher now.
I have two conroller.Along with that there is a languageController which calls an API and receices available lanuages: The result is an array of key value pairs.
Array ( [English] => en [Español] => es [Italiano] => it [Русский] => ru [日本語] => ja )
When I am using render controller , app.request.get('_route') is always null. So I can't dynamically cahnge the path.
li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown-language" role="button"
data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
English
</a>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdown-language">
{% for key,value in languageData %}
<li><a class="dropdown-item" href="{{ path('index', {_locale: value }) }}">{{ key }}</a></li>
{% endfor %}
</ul>
</li>
This is how I render languageController
return $this->render(
'partials/header.html.twig',
['languageData' => $formattedLanguageData,]
);
How can I modify the locale swicher so that I can access multipages(index,view) with my availabe language array.