I have a web application that simply displays a form User Control. I have generated my resx files associated with the User Control by going to the design of the User Control and then clicking Tools > Generate Local Resource
Doing this has created the necessary resx file:
App_LocalResources
ContactUsForm.ascx.resx
I then simply copy and pasted the existing resx file and renamed it so I now have the following:
App_LocalResources
ContactUsForm.ascx.fr-FR.resx
ContactUsForm.ascx.resx
As a test I modified a couple of the dotnet controls text within the new fr-FR resource file just to test whether it was all working as expected and it is not.
I use the following code to set the specific culture information based on a querystring parameter:
protected void Page_Init(object sender, EventArgs e)
{
string cultureName = Request.QueryString["lang"];
if (!string.IsNullOrEmpty(cultureName))
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cultureName);
}
}
I can then simply navigate to the page housing the user control by doing the following:
http://localhost/Default.aspx?lang=fr-FR
I can confirm the culture information is being set by executing the following code:
CultureInfo currentCultureUI = Thread.CurrentThread.CurrentUICulture;
CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;
I can confirm that the set culture is in fact fr-FR however the text is not being replaced as per the changes within the ContactUsForm.ascx.fr-FR.resx file.
I can't seem to get this working as expected. What am I doing wrong and is there any other way to achieve the desired result?
Thanks in advance.
UPDATE:
If I do the following in code it works just fine:
lHeadingResource1.Text = GetLocalResourceObject("lHeadingResource1.Text").ToString();
It's actually reading the correct string from the ContactUsForm.ascx.fr-FR.resx file.
I can also confirm that my controls have all the necessary meta:resourcekey references as well.
It's just strange that if I don't set it in code it defaults back to the default culture and doesn't use the fr-FR specified above.