When you load your page with this "example.com/pt/page" link, change the href and text of the link to English. And when you load the page with "example.com/page", change the href and text to Português.
<a id="lang" href="example.com/pt/page">Português</a>
$(document).ready(function() {
var winLocation = window.location;
var loc = winLocation + "";
if(loc.indexOf("example.com/pt/page") != -1) {
$("#lang").prop("href", "example.com/page");
$("#lang").text("English");
}
else {
$("#lang").prop("href", "example.com/pt/page");
$("#lang").text("Português");
}
});
Update:
If you want to add this link to all pages to your site, then:
1) set class for all the links. Like this:
<a class="lang" href="anything">anything</a>
2) Now modify the jQuery handler like this :
$(document).ready(function() {
var winLocation = window.location;
var loc = winLocation + "";
if(loc.indexOf("/example.com/pt/") != -1) {
$(".lang").prop("href", loc.replace("/example.com/pt/", "/example.com/"));
$(".lang").text("English");
}
else {
$(".lang").prop("href", loc.replace("/example.com/", "/example.com/pt/"));
$(".lang").text("Português");
}
});
Assuming, your Português pages comes under "example.com/pt/" urls and English pages comes under "example.com/"