Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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.

like image 498
ElHaix Avatar asked Dec 29 '22 15:12

ElHaix


1 Answers

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);
like image 96
womp Avatar answered Jan 05 '23 15:01

womp