Force exceptions language in English
Asked Answered
S

7

44

My Visual Studio 2005 is a French one, installed on a French OS. All the exceptions I receive during debug or runtime I obtain also in French.

Can I however do something that the exceptions messages be in English? For goggling, discussing etc.

I tried the following:

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
throw new NullReferenceException();

obtained

Object reference not set to an instance of an object.

This is, surely, cool... but, as I work on a French project, I will not hardcode forcing Thread.CurrentUICulture to English. I want the English change to be only on my local machine, and don't change the project properties.

Is it possible to set the exceptions language without modifying the code of the application?


In VS 2008, set the Tools -> Options -> Environment -> International Settings -> Language to "English" wnd throwing the same exception obtain the ex message en French, however: alt text http://lh4.ggpht.com/_1TPOP7DzY1E/S1V62xcvHAI/AAAAAAAAC7o/ckLDVFPKh5Y/s800/exception.png

Savaii answered 19/1, 2010 at 9:7 Comment(3)
I have the same problem with german with english visual studio and even the compiler erros are localized in german. (Which makes googling them difficult)Spevek
@Christian: See the #721837 maybe this will help you...Savaii
possible duplicate of C# - Exception messages in English?Roderic
S
4

Finally a "sharp" solution could be the following:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
    // Add this; Change the Locales(En-US): Done.
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
#endif

    Application.Run(new Form1());
}

However I'd like a solution without modifications in the project code.

From MSDN:

The CurrentUICulture property will be set implicitly if an application does specify a CurrentUICulture. If CurrentUICulture is not set explicitly in an application's code, it is set by the GetUserDefaultUILanguage function on Windows 2000 and Windows XP Multilingual User Interface (MUI) products where the end user can set the default language. If the user's UI language is not set, it will be set by the system-installed language, which is the language of the operating system's resources.

If an application is Web-based, the CurrentUICulture can be set explicitly in application code to the user's browser accept language.

Savaii answered 19/1, 2010 at 10:45 Comment(0)
W
15

You could set the current culture to English only in debug builds :

#if DEBUG
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#endif
Weighin answered 19/1, 2010 at 9:13 Comment(5)
Wouldn't that make debugging unreliable? Other parts of the project might depend on the France culture.Router
@Thomas: yes, but this change will affect all other code users. If my project manager is a old french man he will decapitate me for that :)Savaii
@Router : most culture-specific behavior like date/time/number formatting depend on the CurrentCulture, not the CurrentUICulture. CurrentUICulture only affects which resources are used. If there are no satellite assemblies for resources in cultures other than French, it will fall back to the default culture anywayWeighin
@serhio: He probably would not decapitate you if you make the UI culture a config setting and configure it only in your personal build to be "en-US".Slr
@divo: yeah, maybe, but I am sure he will not accept as well changes in the actual project only because I want my exceptions in English.Savaii
A
6

For the good of all future users of your application, place this to the Main method:

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

It will save them a good lot of trouble finding the English equivalent of a a badly translated error message.

Alienate answered 9/11, 2017 at 0:53 Comment(0)
E
5

This is known problem. Please vote for fix here: Exception Handling / Error Logging in English

Old Link on Microsoft Connect which has since been decommissioned.

Emptor answered 9/12, 2011 at 7:58 Comment(5)
@Hi-Angel No, it was closed as "not fixed". Could not find any new entry on developercommunity.visualstudio.comDeledda
@LouisSomers I just remember, it was a sarcasm. So subtle though that I didn't see it myself. It probably was a reference to MS ignorance of requests and bugs in general (see e.g. Skype problems).Caffrey
@Caffrey I'm doing another attempt at the DotNet repository on GitHub. Unfortunately I don't have time to fix it myself and ask them to merge it in, but maybe someone else does?Deledda
@LouisSomers sorry, I don't. I have a list of my own things too: adding a few important features to LibreOffice (I'm even thinking of a kickstarter project; it's something I'm looking into ATM), primary clipboard to a Wayland compositor beside Gnome, reading i3-like configs in enlightenment… Just out off top of my head. And even this seems like gonna take veeery long time.Caffrey
Voting has moved here:developercommunity.visualstudio.com/idea/626664/… (chances to fix it are still pretty low)Nicotiana
S
4

Finally a "sharp" solution could be the following:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
    // Add this; Change the Locales(En-US): Done.
    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
#endif

    Application.Run(new Form1());
}

However I'd like a solution without modifications in the project code.

From MSDN:

The CurrentUICulture property will be set implicitly if an application does specify a CurrentUICulture. If CurrentUICulture is not set explicitly in an application's code, it is set by the GetUserDefaultUILanguage function on Windows 2000 and Windows XP Multilingual User Interface (MUI) products where the end user can set the default language. If the user's UI language is not set, it will be set by the system-installed language, which is the language of the operating system's resources.

If an application is Web-based, the CurrentUICulture can be set explicitly in application code to the user's browser accept language.

Savaii answered 19/1, 2010 at 10:45 Comment(0)
G
3

Uninstall the French language pack:

Start - Control Panel - Programs and Functions - Microsoft .NET Framework (4 Client Profile) Language Pack FRU - Uninstall

You may need to repeat the uninstallation for each version of .NET Framework that you find there.

Gauzy answered 4/11, 2011 at 8:42 Comment(0)
F
2

For any Win8/8.1 users facing this issue, installing the English Language Pack and make it the Windows display language seems to be only easy way to resolve it as Win8 has .net framework built in its core.

Probably the same for Win10.

Faraway answered 1/5, 2017 at 4:34 Comment(1)
Not so easy if you have only one language Windows version and it's not English.Longlived
P
0

I didn't try, but according to the documentation that property should be set by default to the current UI language, that is set in the control panel. So it should work correctly automagically according to your international settings.

Pvc answered 19/1, 2010 at 9:44 Comment(10)
what exactly do you mean my "current UI language"? My OS is French one(by e.g. the "Start" button name is "Démarrer"), so by default CultureInfo.CurrentCulture.Name == "fr-FR"Savaii
In ControlPanel I changed the "Regional and language options" => "Standards and formats" to be "English US", but this didn't help.Savaii
I'm talking about the one set in the International settings in the Control Panel (guidebookgallery.org/pics/gui/settings/international/…). EDIT I saw now your comment... I don't know, AFAIK it should work like that...Pvc
@Matteo: you are partially right. I changed the "Standards and formats", and this really changed the CurrentCulture, but NOT changed the Thread's CurrentUICulture : CurrentCulture changed in en-US, but Thread.CurrentThread.CurrentUICulture remained fr-FR.Savaii
I think you can only change UICulture in Regional Settings if you have an MUI version of Windows. I think the setting is Regional and Language Options / Languages / Language used in menus and dialogs (on XP).Latarsha
You're right: although the regional settings always had effect on the language of the resources retrieved by the unmanaged APIs, the CurrentUICulture is said on the docs to be initialized by default to the value provided by GetUserDefaultUILanguage, whose doc says that "If MUI is not installed on the operating system, the function retrieves the default computer user interface language." Anyhow, now that we know how it works, you could just set CurrentUICulture to the CultureInfo of CurrentCulture. --- EDIT --- I saw just know that you figured it out by yourself. :PPvc
@Matteo: yes, but you know, this didn't help me much as I can't(don't want) change the solution code for that, because this will affect not only me.Savaii
Making the descriptions of the exceptions match the preferred language of the user for me it's a bonus also for the end users.Pvc
FWIW, on Windows 7 (English) if you install optional language packs then you can change the "display language" on a per-user basis (essentially, MUI is built-in). This is probably the easiest way to handle this short of just adding an option to the program.Panchito
I didn't try Windows 7, but as far as I remember the .NET Framework is localized separately from Windows, and the various language packs are freely installable on every machine, so setting the CurrentUICulture to the desidered one should work on every machine that has the needed language pack (usually on every machine there's the "normal" Framework in English plus the local language pack).Pvc

© 2022 - 2024 — McMap. All rights reserved.