我一直在开发多语言应用程序。现在有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?
答案 0 :(得分:0)
我也在项目中使用了全局资源。它有效,我从不使用当地的。但是当你初始化文化时我发现了一个问题。我认为你应该在基页中重写initializeCulture方法。在申请中。它将改变使用该网站的所有用户文化。
protected override void InitializeCulture()
{
System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = culture;
base.InitializeCulture();
}