ASP.NET MVC: localization problems (invalid resx file for culture)

I have a file Strings.resx and Strings.nl.resx . The first contains the English string, the other the Dutch string. They are part of the C# Class Library : Module project.

  public static string testString() { //I Force the culture to always be english Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); return Strings.Hello; } 

When I call them from a simple Console Application , it works:

  Console.WriteLine(Module.testString()); //English string gets returned 

When I do the same with my ASP.NET MVC application, I get the Dutch version ...

  public ActionResult testCulture() { return Content(Module.testString()); //Dutch string gets returned..?! } 

I am using Dutch Windows, so any automatic configuration will be Dutch.But, how can I get a different line when the culture is hard-coded en-us in the class library?

What am I missing here?

+4
source share
2 answers

Do you have a neutral resource? If it is set to "nl" or "nl-NL" , any request for a resource that is not found will ultimately result in the extraction of the resource "nl" . Since you do not have Strings.en-US.resx or Strings.en.resx , setting CurrentUICulture to "en-US" will force the system to use the language of neutral resources.

+3
source

check if your web.config has a globalization tag whose language is set to Dutch

or

if you use Internet Explorer, go to "Tools"> "Internet" and click on the "Language" button, if it shows Dutch before English, change it

0
source

Source: https://habr.com/ru/post/1303808/


All Articles