0

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.

Mattew
  • 1
  • 1
  • "*When I am using render controller , app.request.get('_route') is always null.*" - You didn't post this part of the code? – DarkBee Jun 26 '23 at 12:14
  • What do you mean with "*I can't dynamically change the path*"? Twig is rendered serverside, if you want to do something clientside you would need to resort to javascript. Consider "caculating" the different paths beforehand and adding them as an `data-xxxx` attribute to your HTML – DarkBee Jun 26 '23 at 12:16

0 Answers0