下に 2 つの Resources ファイルがありますApp_GlobalResources
MyApp.resx
MyApp.sv.resx
知らない人のために:スウェーデンの UICultureをMyApp.resx
除くすべての言語がフォールバックします。MyApp.sv.resx
そして、私はプロパティが次のように異なる方法で呼び出される<asp:Label>
魔女の3を示す簡単なページを持っています:Text
<i>using Resource.Write:</i><br />
<asp:Label ID="Label1" runat="server" />
<hr />
<i>using HttpContext.GetGlobalResourceObject:</i><br />
<asp:Label ID="Label2" runat="server" />
<hr />
<i>using Text Resources:</i><br />
<asp:Label ID="Label3" runat="server"
Text="<%$ Resources:MyApp, btnRemoveMonitoring %>" />
<p style="margin-top:50px;">
<i>Current UI Culture:</i><br />
<asp:Literal ID="litCulture" runat="server" />
</p>
Label3
ページで呼び出されるのは 1 つだけで、最初の 2 つは次のように設定されます。
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label1.Text = Resources.AdwizaPAR.btnRemoveMonitoring;
Label2.Text = HttpContext.GetGlobalResourceObject("MyApp", "btnRemoveMonitoring").ToString();
litCulture.Text = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
}
}
ブラウザ言語を使用するとすべて正常に動作しますが、その設定をオーバーライドし、他の入力に基づいて正しい翻訳をロードしたいので、UICulture
使用する andを上書きする必要があります。
protected void Page_Init(object sender, EventArgs e)
{
Page.Culture = "en-US";
Page.UICulture = "en-US";
}
witch は次と同じです。
protected void Page_Init(object sender, EventArgs e)
{
System.Globalization.CultureInfo cinfo = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
System.Threading.Thread.CurrentThread.CurrentCulture = cinfo;
System.Threading.Thread.CurrentThread.CurrentUICulture = cinfo;
}
このすべてで、私が得ているのはこれです:
言い換えれcode-behind
ば、正しいテキストを設定するために使用する場合にのみ、正しいローカライズが得られます。すべてのinline
ローカライズは単にブラウザー言語を使用します。
私は何が欠けていますか?