I have a site with 2 languages that are En and Th. Each language has the same file name in different folder, i.e. /en/ and /th/. I've created <a> tag to switch between these 2 languages on my included header file (asp).
The question is how to get the current path wherever you are, and change folder name to en or th? (If you are inside English Contact page, clicking th will take you to Thai Contact page.)
I have tried to create a function:
<script>
function changeLanguage(to) {
var from = jQuery.url.segment(-2);
var url = from.replace('/' + from + '/', to);
document.location = url;
}
</script>
to use in <a> tag.
<a id="flags" href="#" onclick="changeLanguage(en)"> English </a>|<a href="#" onclick="changeLanguage(th)" >Thai</a>
But it does not work. I've spent so many days to find a similar question. I found some but still couldn't apply to my code. So please help me. I'm really newbie on this and really need your help. Thank you very much.
var url = from.replace('/' + from + '/', to);statement change your www.domain.com/en/ to www.domain.comth ? Is produced url correct?