I have a Visual Studio C# .NET project. I have two master templates. One for the original website in english. And a second master page for the Spanish version of the website.
In both master pages, there’s a link that says “English” (or Spanish). This link will take the user to the translation of the website in the other language.
But If I am in the “About Us” page in english, and I click in the SPANISH link, it will take me to the Home Page in spanish and not to the current page (in this case About Us) in spanish. How can I set the Link in the master page, to know what page translation i want ?
I have no idea how to code this thing.
Thanks.
SOLUTION – SOLVED
<script type="text/javascript">
function SetLanguageLinkUrl() {
var url = location.href;
var newURL;
// Create block of these, for each set of pages in different languages.
if (url.indexOf("inicio") > 0)
newURL = url.replace("/es/inicio.aspx", "/en/index.aspx");
else if (url.indexOf("index") > 0)
newURL = url.replace("/en/index.aspx", "/es/inicio.aspx");
// The Redirect
window.location = newURL;
}
</script>
Assuming you have an
HtmlAnchorin your masterpage, you could replace the language folder in the link with the other language folder in your url.UPDATE
If you want to translate the url, you’re maybe best having a dictionary of urls to use as a lookup table.