0

以下信息都是关于在法国显示语言的。但它没有显示任何数据,为什么?我尝试了很多方法,但没有用。我尝试了很多方法,但没有用。我尝试了很多方法,但没有用。

     <?xml version="1.0" encoding="utf-8" ?>
     <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" enableLocalization="true">      
            <siteMapNode ur!="~/Default2.aspx" title="$resources:SiteMapLocalizations,str1" description=""/>
    </siteMap>

     <asp:Menu ID="MnuSideMenu" CellPadding="0" CellSpacing="0" runat="server" Width="100%">
        <DataBindings>
            <asp:MenuItemBinding DataMember="siteMapNode" NavigateUrlField="url" TextField="title" />
        </DataBindings>
    </asp:Menu>        

public partial class Default2 : System.Web.UI.Page
  {
protected void Page_Load(object sender, EventArgs e)
{
    XmlDataSource oXmlDataSource = new XmlDataSource();
    oXmlDataSource.XPath = "siteMap/siteMapNode";
    oXmlDataSource.DataFile = Server.MapPath("~") + @"/siteMap/x.sitemap";
    MnuSideMenu.DataSource = oXmlDataSource;
    MnuSideMenu.DataBind();
}
protected override void InitializeCulture()
{
    string languageId = "en-US";
    if (!string.IsNullOrEmpty(languageId))
    {
        if (languageId.EndsWith("FR")) languageId = "fr-FR";
        else languageId = "en-US";
        SetCulture(languageId);
    }

    if (Session["Language"] != null)
    {
        if (!Session["Language"].ToString().StartsWith(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)) SetCulture(Session["Language"].ToString());
    }

    base.InitializeCulture();
}

protected void SetCulture(string languageId)
{
    Session["Language"] = languageId;
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(languageId);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageId);
}
protected void Button1_Click1(object sender, EventArgs e)
{

}

}

在此处输入图像描述


4

2 回答 2

0

添加Global.asax文件写这段代码

void Application_BeginRequest(Object sender, EventArgs e)
    {
        // Code that runs on application startup
        HttpCookie cookie = HttpContext.Current.Request.Cookies["CultureInfo"];
        if (cookie != null &amp;&amp; cookie.Value != null)
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cookie.Value);
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cookie.Value);
        }
        else
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");
        }
    }

更多详情请点击

http://satindersinght.blogspot.in/2012/06/create-website-for-multilanguage.html


样品

 <siteMapNode url="EmployeeDetails.aspx " title="$resources:Resources,EmployeeDetails " description="$resources:Resources,Viewemployeedetails" />

注意:资源是主根,如给定链接中所示

于 2012-06-26T12:44:38.613 回答
0

本地化不适用于 XmlDataSource。所以我删除了 XmlDataSource 并使用了

        SiteMapDataSource  oSmapDataSource = new SiteMapDataSource();
        oSmapDataSource.SiteMapProvider= "siteMapCatalogueSiteMap";
        oSmapDataSource.ShowStartingNode = false; // Just a Dummy node as we dont have the Root node for Localisation concept
        (this.Master.FindControl("MnuSideMenu") as Menu).DataSource = oSmapDataSource;
        (this.Master.FindControl("MnuSideMenu") as Menu).DataBind();

现在印度尼西亚语来了。

于 2012-06-27T13:05:30.950 回答