Locale Swicher for multipages with render controller

I am trying to add language switcher and Locale was 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">
        <li><a class="dropdown-item" href="{{ path('index', {_locale: 'en'}) }}">English</a></li>
        <li><a class="dropdown-item" href="{{ path('index', {_locale: 'fr'}) }}">Français</a></li>
    </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.