我希望在主页上有一个西班牙语/英语链接,该链接将带您到其他语言的当前页面,而不是“主页”页
我有一个 Visual Studio C# .NET 项目。我有两个主模板。一个是英文原始网站。以及该网站西班牙语版本的第二个母版页。 在两个母版页中,都有一个显示“英语”(或西班牙语)的链接。此链接会将用户带到其他语言的网站翻译。
但是,如果我在英文的“关于我们”页面,然后单击西班牙语链接,它将带我进入西班牙语主页,而不是西班牙语的当前页面(在本例中为关于我们)。如何在母版页中设置链接,以了解我想要的页面翻译?
我不知道如何编写这个东西。
谢谢。
解决方案 - 已解决
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有一个
HtmlAnchor
在母版页中,您可以将链接中的语言文件夹替换为网址中的其他语言文件夹。更新
如果你想翻译网址,你最好有一个网址字典用作查找表。
Assuming you have an
HtmlAnchor
in 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.