Welcome Guest, Not a member yet? Register   Sign In
Change language dynamically CI 4.4.6
#2

I am using the following code:
In the top navigation, I have a dropdown menu:
Code:
<ul aria-labelledby="dropdownSubMenu1" class="dropdown-menu border-0 shadow">
     <li><a href="<?= base_url(); ?>/lang/set_language/en/<?= str_replace('/', '~', current_url()); ?>" class="dropdown-item"><?=lang('Language.English')?> </a></li>
     <li><a href="<?= base_url(); ?>/lang/set_language/nl/<?= str_replace('/', '~', current_url()); ?>" class="dropdown-item"><?=lang('Language.Dutch')?> </a></li>
</ul>

I have a controller in a folder language with the following code to set the language:
PHP Code:
public function set_language()
    {
        // Get the language id
        $uri current_url(true);
        $total $uri->getTotalSegments();
        // get the language id
        $id $uri->getSegment($total-1);

        // Get the url to go to after this
        $redirect str_replace ("~""/"$uri->getSegment($total));
        $session session();
        $session->remove('language');
        $session->set('language'$id);
        return redirect()->to($redirect);
    

This changes the language without changing the url.
Reply


Messages In This Thread
RE: Change language dynamically CI 4.4.6 - by JustJohnQ - 03-13-2024, 08:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB