添加全球资源语言后,如何为客户提供选择哪种语言的选项?

发布于 2024-12-27 22:39:02 字数 684 浏览 2 评论 0原文

我在公司网站上的英语中添加了 3 种其他语言(fr、es-mx、de),它们都工作正常。我按照MSDN 创建本地化的演练进行操作。

我正在使用 Visual Studio 2010 / VB / dot-net 4.0,并且我的所有页面的顶行中已经有这样的内容:

  <%@ Page Title="USS Products & Services" Language="VB" MasterPageFile="~/products/products.Master" AutoEventWireup="false"
CodeFile="default.aspx.vb" Inherits="default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>

我的 global_apps 目录中有 4 个全局资源 (.resx) 文件。但是,如果我不想只让浏览器检测他们的语言怎么办?我想让他们选择自己的语言。

我如何为客户提供 4 个标志之间的选项(每种语言 1 个)并让他们选择?或者也许是滚动站点地图类型的效果,他们可以将鼠标悬停在一种语言上并选择它?任何帮助将不胜感激!谢谢!

I have added 3 additional languages (fr, es-mx, de) to English in my company's website, and they're all working fine. I followed the MSDN walkthrough on creating localization.

I'm using Visual Studio 2010 / VB / dot-net 4.0 and I already have in my top line on all of my pages, this:

  <%@ Page Title="USS Products & Services" Language="VB" MasterPageFile="~/products/products.Master" AutoEventWireup="false"
CodeFile="default.aspx.vb" Inherits="default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>

I have 4 global resource (.resx) files in my global_apps directory. But what if I don't want just the browser alone to detect their language? I want to give them the option of choosing their own language.

How do I give the client the option between 4 flags -- 1 for each language -- and let them choose? Or maybe a rollover sitemap type of effect, where they can mouse over a language and choose it? Any help would be appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2025-01-03 22:39:02

尝试这个简单的方法:
我已经在下拉列表中定义了语言,并有一个按钮选择

<asp:DropDownList ID="ddlCulture" DataTextField="DisplayName" DataValueField="Name"
         runat="server" >
        <asp:ListItem Value="es-MX">Spanish</asp:ListItem>
        <asp:ListItem Value="en-US">English</asp:ListItem>
    </asp:DropDownList>
<asp:Button ID="btnSelect" Text="Select" runat="server" OnClick="btnSelect_Click" />

“立即”代码:

protected void btnSelect_Click(object sender, EventArgs e)
   {
        Session["uiculture"] = ddlCulture.SelectedValue;
        Session["culture"] = ddlCulture.SelectedValue;
        Response.Redirect(Request.Path);
   }

    protected override void InitializeCulture()
    {
      if(Session["culture"]!=null)
        UICulture=Session["culture"].ToString();
    }

更新:抱歉,我忘记了覆盖关键字。现在包含它应该可以工作。

顺便说一句,你正在使用 VB,抱歉我没有看到这个。等效代码是:

 Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As EventArgs)
    Session("uiculture") = ddlCulture.SelectedValue
    Session("culture") = ddlCulture.SelectedValue
    Response.Redirect(Request.Path)
End Sub
Protected Overrides Sub InitializeCulture()
    If Not Session("culture") Is Nothing Then
        UICulture = Session("culture").ToString()
    End If
End Sub

Try this simple method:
I've defined the languages in a dropdownlist and have a button select

<asp:DropDownList ID="ddlCulture" DataTextField="DisplayName" DataValueField="Name"
         runat="server" >
        <asp:ListItem Value="es-MX">Spanish</asp:ListItem>
        <asp:ListItem Value="en-US">English</asp:ListItem>
    </asp:DropDownList>
<asp:Button ID="btnSelect" Text="Select" runat="server" OnClick="btnSelect_Click" />

Now Code:

protected void btnSelect_Click(object sender, EventArgs e)
   {
        Session["uiculture"] = ddlCulture.SelectedValue;
        Session["culture"] = ddlCulture.SelectedValue;
        Response.Redirect(Request.Path);
   }

    protected override void InitializeCulture()
    {
      if(Session["culture"]!=null)
        UICulture=Session["culture"].ToString();
    }

Update: Sorry I forgot the override keyword. Now included it should work.

By the way, you're using VB, sorry I'vent seen this. The equivalent code is:

 Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e As EventArgs)
    Session("uiculture") = ddlCulture.SelectedValue
    Session("culture") = ddlCulture.SelectedValue
    Response.Redirect(Request.Path)
End Sub
Protected Overrides Sub InitializeCulture()
    If Not Session("culture") Is Nothing Then
        UICulture = Session("culture").ToString()
    End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文