Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a different language for ASP.NET MVC errors

I have an ASP.NET MVC application configured for Portuguese, on Visual Studio 2015. While debugging this application, I've set <customErrors mode="Off" />, but all errors are shown in Portuguese, and I want to see them in English.

I tried to set this in Web.config:

<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="true" />

In Global.asax I tried:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

and

Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

I also uninstalled the Nuget package Microsoft.AspNet.Mvc.pt-br, no success.

This question is similar, but I need a solution that doesn't involve changing the machine's configuration or installed components, as that's not allowed in my workplace.

How can I make all error messages show in a specific language (in this case, English)?

like image 944
Marcos Dimitrio Avatar asked Nov 23 '15 17:11

Marcos Dimitrio


1 Answers

Today when I tried this again, to my surprise the messages were in English (almost, see below). I tried to reproduce the error I had yesterday, but I couldn't.

Perhaps it is just a matter of restarting (VS or the PC). I also kept working on the project at night on a different PC, but not on anything related with this issue, so I can't say it made a difference. All I have set up in Web.config is:

<globalization uiCulture="en-US" culture="en-US" enableClientBasedCulture="true" />

But still not everything was in English. While trying to reproduce the error, I forced a library load error, I used a DLL that requires Ninject to be installed. The error message was (emphasis mine on the translated part):

Server Error in '/' Application. Could not load file or assembly 'Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. O sistema não pode encontrar o arquivo especificado.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

That part was supposed to be: The system cannot find the file specified.

In that case, I don't think there is much that can be done programmatically only.

like image 62
Marcos Dimitrio Avatar answered Oct 17 '22 05:10

Marcos Dimitrio