Language change in PHP site according to link

Asked

Viewed 741 times

0

I have a PHP site in three languages. I even have a changeLang(lang) function that perfectly changes the language from Portuguese to English or Spanish. However, the link on my page always stays the same, even when I change the language:

http://www.minhapagina.com/phase01?lang=pt-br

I wish I had the option to change the language to English (Eng) or Spanish (esp) when I change the link too. I tried something like this at the beginning of page phase01.php, but it did not work:

if(isset($_GET['lang'])){
    if($_GET['lang'] == 'eng'){
        echo "<script>window.addEventListener('DOMContentLoaded', function () { changeLang(1); }, false);</script>";
    }
    elseif($_GET['lang'] == 'esp'){
        echo "<script>window.addEventListener('DOMContentLoaded', function () { changeLang(2); }, false);</script>";
    }
    else {
        echo "<script>window.addEventListener('DOMContentLoaded', function () { changeLang(0); }, false);</script>";
    }
}

What I could do?

  • 1

    Use an onclick event to change the language without passing the reference on each link.

  • In this case, changeLang is already an event that I have onClick on my site (has the language option in the page header) and works well. But even with the change of language the link does not change, always getting lang=en. In fact, I took over this site from another developer, so I’m having to chase after a lot of things on it.

  • Show how you’re creating links.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.