Вы можете посмотреть на историю JS объекта:
function changeLanguage(code){
//possible languages
var codes=["en","de"];
if(!codes.find(function(a){return a==code})){
//language not available
console.error("unknown language");
return;
}
//get current url
url=window.location.pathname;
for(i=0;i<codes.length;i++){
//replace current language with new language
url=url.replace(codes[i],code);
}
//"redirect" url without reloading the page
history.pushState({},"new title",url);
//replace content...
}
//example:
changeLanguage("de");
Это требует URL содержать код языка:
http://example.com/en/main/
->
http://example.com/de/main/
См history.pushState –