【问题标题】:globalization in asp to change language french,urdu, english to dropdown listASP中的全球化将语言法语,乌尔都语,英语更改为下拉列表
【发布时间】:2015-05-08 08:52:09
【问题描述】:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="amenities.aspx.cs" Inherits="amenities"%>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server" >

    <div>

        Change Language
    
       <br />
   <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" >
       <asp:ListItem Value="en-US">English</asp:ListItem>
       <asp:ListItem Value="ur">Urdu</asp:ListItem>
       <asp:ListItem Value="fr">French</asp:ListItem>
        </asp:DropDownList>
    </div>
 
    <div>
        <img src="Images/2.jpg" style="position:relative;top:20px; height:300px;" />
        <p style="position:relative;left:454px; top: -300px; width: 619px;"><asp:Label ID="Label2" runat="server" BackColor="<%$ Resources:Resource, BColor %>" ForeColor="<%$ Resources:Resource, FColor %>" Text="<%$ Resources:Resource, Text %>" ></asp:Label></p>


        <br /><img src="Images/3.jpg" style="position:relative; height:305px; top: -120px; left: 2px;" />
        <p style="position:relative;left:456px; top: -443px; width: 619px; bottom: 2332px;"><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></p>


        <br/><img src="Images/4.jpg" style="position:relative;top:-180px; height:330px; left: 5px; width: 450px;" />
        <p style="position:relative; top: -530px; left: 460px; width: 617px;">The spectacular happens at all of our hotels and resorts in 80 countries across six continents. Let us find the one that’s right for you. The five-star international Islamabad Marriott Hotel is located at the foot steps of the famous Margalla Hills and is within close proximity to Rawal Lake, the town centre, President & Prime Minister Houses, Ministry of Foreign Affairs, Senate, Parliament House, Foreign Missions, World Bank, Government Offices, corporate sector, Print and Electronic media offices etc. The Hotel is a favourite rendezvous of politicians, diplomats, businessmen and movers and shakers of the country. Owing to the perfect location of the hotel, it hardly takes half an hour to commute between the Hotel, the Islamabad International Airport and the places of interests.</p>


        <br/><img src="Images/5.jpg" style="position:relative; top: -372px; left: 488px; width: 587px; height: 249px;" />
        <p style="position:relative; top: -638px; left: 1px; width: 481px;">The all-day dining restaurant offers an extensive selection of international & local flavors on a la carte menu but also buffet available for breakfast,lunch,hi-tea and dinner.The restaurant is popular for business lunches,casual dinners and Sunday Brunch</p>
         
        <br/><img src="Images/6.jpg" style="position:relative; top: -424px; left: 485px; height: 276px; width: 590px;" />
        <p style="position:relative; top: -718px; left: 2px; width: 478px;">A truly authentic Japenese Restaurant. As you dine with us you will not only savour the sumptous flavour but also the spectacular design that actually makes you feel that you are actually in Japan. Sakura is made to capture your heart and soul imagination. Jason's steakhouse concept is centered around exceptionally high quality food and warm elegent atmosphere. we serve best steak available and uncompromising quality.Two Private Rooms, both with the capacity of 04-persons.</p>
        
         </div>       
   </asp:Content>

我正在尝试在 asp 中使用全球化。我创建了三个资源文件,frurresource。语言正在通过下拉列表选择进行更改,但我也必须在同一页面上使用下拉列表更改其他语言。
box1 语言已更改,但如何更改box2 语言?
我在resource 文件中遇到问题,如何将 2 3 和 4 文本放在同一资源 fr 资源文件中,以及如何将每个资源文件与不同标签的标签链接起来。

http://prntscr.com/72uhug请看截图 http://prntscr.com/72um08资源文件截图

【问题讨论】:

  • 你能贴一些代码吗?

标签: asp.net


【解决方案1】:

首先,让自己熟悉concept of Globalization here 并了解完全处理您的需求的全局和本地资源文件的使用。给出了一个简单的定义here too

因此,简而言之,您应该更好地为每种语言生成本地资源并覆盖InitializeCulture() 方法以设置页面的UICulture 属性,以便在dropdownlist 选择更改时选择适当的语言特定文件。

第 1 步: 生成特定于语言的资源文件 (.resx)

  1. 选择选项:工具 -> 在您的视觉对象中生成本地资源 工作室。如果假设您的 aspx 文件名为:default.aspx,则 Visual Studio 创建一个名为 App_LocalResources 的新文件夹,然后 在App_LocalResources 文件夹中,一个名为 default.aspx.resx。在这个default.aspx.resx,你应该把 中性语言(英文)文本。
  2. 接下来,创建一个特定于法语的资源文件

    在解决方案资源管理器中,右键单击 default.aspx.resx 文件,然后
    点击复制。

    右击App_LocalResourcesfolder,然后点击粘贴。

    Visual Studio 创建一个名为 Copy of default.aspx.resx 的文件。

    将其重命名为default.aspx.fr.resx。这个资源文件代表现在 法语页面内容。

    打开default.aspx.fr.resx 并添加您的法语文本。

  3. 以同样的方式为乌尔都语创建特定语言的资源文件。 [ 文件名 因此将是:default.aspx.ur.resx]

第 2 步:
请记住,Asp.Net 将选择适当的特定语言 基于 Pages 的 UICulture 值的资源文件。设置 UiCulture Page 的属性,您必须覆盖 IntializeCulture() 方法并在此处设置此属性:

// 使用 Request.Form["DropDownList1"] 访问 DropDownlist 值

protected override void InitializeCulture()
{
    if (Request.Form["DropDownList1"] != null)
    {
        String selectedLanguage = Request.Form["DropDownList1"];
        UICulture = selectedLanguage ;
        Culture = selectedLanguage ;
        Thread.CurrentThread.CurrentCulture = 
            CultureInfo.CreateSpecificCulture(selectedLanguage);
        Thread.CurrentThread.CurrentUICulture = new 
            CultureInfo(selectedLanguage);
    }
    base.InitializeCulture();
}

Read here 获取有关使用 Asp.net 创建多语言网站的详细教程

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    相关资源
    最近更新 更多