【发布时间】:2012-02-29 16:33:24
【问题描述】:
我一直在开发多语言应用程序。现在有2种语言。土耳其语和英语。全球资源一切正常。但是本地资源效果不佳。让你看看我的代码。我的代码 global.asax 和 login.aspx。还将 resx 文件作为全局和本地文件。
在我的 login.aspx 中:
protected void btnEng_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies["language"];
if (cookie == null) cookie = new HttpCookie("language");
cookie.Value = "en-US";
Response.SetCookie(cookie);
Response.Redirect("Login.aspx");
}
protected void btnTurk_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies["language"];
if (cookie == null) cookie = new HttpCookie("language");
cookie.Value = "tr-TR";
Response.SetCookie(cookie);
Response.Redirect("Login.aspx");
}
Global.asax:
protected void Application_BeginRequest(object sender, EventArgs e)
{
// Dil ayarları cookie'den okunuyor.
string lang = "tr-TR"; // Dil varsayılan olarak Türkçe
System.Web.HttpCookie cookie = new System.Web.HttpCookie("language");
cookie = Request.Cookies["language"];
if (cookie != null && cookie.Value != null)
lang = cookie.Value;
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
}
一切正常。如果我使用全局 resx:
<ext:TextField
ID="txtUsername"
runat="server"
FieldLabel="<%$ Resources: ResourceMetrics , kullanici %>"
AllowBlank="false"
BlankText="Your username is required."
Text="Demo"
AnchorHorizontal="100%"
/>
但如果我使用本地资源,
<ext:Label ID="Label1" runat="server" meta:resourcekey="LabelResource1" Text="vxvccccccccccccccccccccccccccccc">
不工作! resx如何使用本地资源?
【问题讨论】:
标签: c# asp.net .net visual-studio c#-4.0