I have two Resources files under App_GlobalResources
MyApp.resx
MyApp.sv.resx
for those who don't know: All languages will fallback to MyApp.resx
except the Swedish UICulture will use the MyApp.sv.resx
and I have a simple page that shows 3 <asp:Label>
in witch the Text
property is called differently like:
<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
is the only one called on Page, the first 2 are set like:
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;
}
}
if I use the browser language all works fine, but I want to override that setting and load the correct translation based on other input, so I need to overwrite the UICulture
and for that I use:
protected void Page_Init(object sender, EventArgs e)
{
Page.Culture = "en-US";
Page.UICulture = "en-US";
}
witch is the same as:
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;
}
with all this, what I'm getting is this:
In other words I'm getting the correct localization only if I use code-behind
to set the correct text, all inline
localization simply uses the browser language.
What am I missing?