Search code examples
c#asp.netlocalizationresx

.resx Localization not working with ASP.Net - C#


I've created two .resx files - WebResources.resx and WebResources.fr-FR.resx.

Both contain ExceptionMessages_SignupWithCard.

To test I did:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Response.Write("Current Culture is " + CultureInfo.CurrentCulture.EnglishName);
Response.Write("<br>Message is: " + Resources.WebResources.ExceptionMessages_SignupWithCard);

The problem is that I still get the ExceptionMessages_SignupWithCard message from WebResources.resx and not the one from WebResources.fr-FR.resx .

Can someone please assist?

Thanks.


Solution

  • ASP.Net (specifically, the ResourceManager) uses CurrentUICulture to retrieve resources.

    Try setting the Thread's CurrentUICulture as well.

    CultureInfo french = new CultureInfo("fr-FR");
    Thread.CurrentThread.CurrentCulture = french;
    Thread.CurrentThread.CurrentUICulture = french;
    Response.Write("Current Culture is " + CultureInfo.CurrentCulture.EnglishName);
    Response.Write("<br>Message is: " +  
              Resources.WebResources.ExceptionMessages_SignupWithCard);