単純。アプリケーションをローカライズしたい。私は何日もグーグルで検索し、リソースに到達するために何百万もの異なるアプローチを試みました. 私が成功した唯一の方法は、標準のasp.netフォルダー「App_LocalResource」を使用して、リソースファイルを公開し、Custom Tool Name
. Custom Tool Name
ビューで、 with をインポートでき@using
ます。
私の問題は、カルチャを変更しても言語/リソース項目が変更されないことです。
global.asax で変更する方法は次のとおりです。
protected void Application_AcquireRequestState(object sender, EventArgs e)
{
if (HttpContext.Current.Session != null)
{
CultureInfo ci = (CultureInfo)this.Session["Culture"];
if (ci == null)
{
string langName = "en";
string autoLang = "";
if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length != 0)
{
autoLang = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
if (autoLang == "da")
langName = autoLang;
ci = new CultureInfo(langName);
this.Session["Culture"] = ci;
}
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
}
したがって、文化は または のいずれda
かen
です。しかし、リソース ファイルの名前には特定の構文が必要であることに気付きました。国/文化コードのないデフォルト (この場合は英語) が必要であり、その他のデフォルトは reFile.da-DK.resx のように名前が付けられています。言語コードとカルチャ コードの両方が必要です。
カルチャが「da-DK」ではなく「da」に設定されているため、リソース ハンドラが私のファイルを認識できるのではないかと心配しています。da
リソース ファイルに resFile.da.resxという名前を付けると、リソース ファイルをインポートできませんCustom Tool Name
。
これを解決するにはどうすればよいですか?